Commit 607294a4 by Qiang Xue

Fixes #2821: Console help command incorrectly lists non-console controllers as available commands

parent bf599b96
......@@ -8,6 +8,7 @@ Yii Framework 2 Change Log
- Bug #2314: Gii model generator does not generate correct relation type in some special case (qiangxue)
- Bug #2563: Theming is not working if the path map of the theme contains ".." or "." in the paths (qiangxue)
- Bug #2801: Fixed the issue that GridView gets footer content before data cells content (ElisDN)
- Bug #2821: Console help command incorrectly lists non-console controllers as available commands (qiangxue)
- Bug #2853: ActiveRecord did not handle resource-typed columns well (chris68, qiangxue)
- Bug #3042: `yii\widgets\Pjax` should end application right after it finishes responding to a pjax request (qiangxue)
- Bug #3066: `yii\db\mssql\Schema::getTableSchema()` should return null when the table does not exist (qiangxue)
......
......@@ -157,7 +157,10 @@ class HelpController extends Controller
$files = scandir($controllerPath);
foreach ($files as $file) {
if (strcmp(substr($file, -14), 'Controller.php') === 0) {
$commands[] = $prefix . Inflector::camel2id(substr(basename($file), 0, -14));
$controllerClass = $module->controllerNamespace . '\\' . substr(basename($file), 0, -4);
if ($this->validateControllerClass($controllerClass)) {
$commands[] = $prefix . Inflector::camel2id(substr(basename($file), 0, -14));
}
}
}
}
......@@ -166,6 +169,21 @@ class HelpController extends Controller
}
/**
* Validates if the given class is a valid console controller class.
* @param string $controllerClass
* @return bool
*/
protected function validateControllerClass($controllerClass)
{
if (class_exists($controllerClass)) {
$class = new \ReflectionClass($controllerClass);
return !$class->isAbstract() && $class->isSubclassOf('yii\console\Controller');
} else {
return false;
}
}
/**
* Displays all available commands.
*/
protected function getHelp()
......
......@@ -19,6 +19,7 @@ require(__DIR__ . '/Yii.php');
$application = new yii\console\Application([
'id' => 'yii-console',
'basePath' => __DIR__ . '/console',
'controllerNamespace' => 'yii\console\controllers',
]);
$exitCode = $application->run();
exit($exitCode);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment