* @since 2.0 */ class HelpController extends \yii\console\Controller { public function actionIndex($args = array()) { echo "Yii console command helper (based on Yii v" . \Yii::getVersion() . ").\n"; $commands = $this->getCommands(); if ($commands !== array()) { echo "\n Usage: yiic [...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 \n"; } else { echo "\nNo commands are found.\n"; } } protected function getCommands() { $commands = $this->getModuleCommands(\Yii::$application); sort($commands); return array_unique($commands); } /** * @param \yii\base\Module $module * @return array */ protected function getModuleCommands($module) { if ($module === null) { return array(); } $commands = array_keys($module->controllers); foreach ($module->getModules() as $id => $module) { foreach ($this->getModuleCommands($module->getModule($id)) as $command) { $commands[] = $command; } } $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; } }