Yii2 Bootstrap 3
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.0 KiB

13 years ago
<?php
/**
13 years ago
* HelpController class file.
13 years ago
*
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2012 Yii Software LLC
13 years ago
* @license http://www.yiiframework.com/license/
*/
13 years ago
namespace yii\console\commands;
13 years ago
/**
* HelpCommand represents a console help command.
13 years ago
*
* HelpCommand displays the available command list or the help instructions
13 years ago
* about a specific command.
*
* To use this command, enter the following on the command line:
13 years ago
*
* ~~~
* yiic help [command name]
* ~~~
*
13 years ago
* In the above, if the command name is not provided, it will display all
* available commands.
*
* @property string $help The command description.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
13 years ago
class HelpController extends \yii\console\Controller
13 years ago
{
13 years ago
public function actionIndex($args = array())
{
13 years ago
echo "Yii console command helper (based on Yii v" . \Yii::getVersion() . ").\n";
$commands = $this->getCommands();
if ($commands !== array()) {
echo "\n Usage: yiic <command-name> [...options...]\n\n";
echo "The following commands are available:\n";
foreach ($commands as $command) {
echo " - $command\n";
}
echo "\nTo see individual command help, enter:\n";
echo "\n yiic help <command-name>\n";
} else {
echo "\nNo commands are found.\n";
}
}
13 years ago
13 years ago
protected function getCommands()
{
$commands = $this->getModuleCommands(\Yii::$application);
sort($commands);
return array_unique($commands);
13 years ago
}
13 years ago
/**
13 years ago
* @param \yii\base\Module $module
* @return array
13 years ago
*/
13 years ago
protected function getModuleCommands($module)
13 years ago
{
13 years ago
if ($module === null) {
return array();
13 years ago
}
13 years ago
$commands = array_keys($module->controllers);
foreach ($module->getModules() as $id => $module) {
foreach ($this->getModuleCommands($module->getModule($id)) as $command) {
$commands[] = $command;
13 years ago
}
13 years ago
}
13 years ago
13 years ago
$files = scandir($module->getControllerPath());
foreach ($files as $file) {
if(strcmp(substr($file,-14),'Controller.php') === 0 && is_file($file)) {
$commands[] = lcfirst(substr(basename($file), 0, -14));
}
}
return $commands;
13 years ago
}
}