mirror of
				https://github.com/yiisoft/yii2.git
				synced 2025-11-04 14:46:19 +08:00 
			
		
		
		
	Fixes #2821: Console help command incorrectly lists non-console controllers as available commands
This commit is contained in:
		@ -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 #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 #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 #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 #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 #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)
 | 
					- Bug #3066: `yii\db\mssql\Schema::getTableSchema()` should return null when the table does not exist (qiangxue)
 | 
				
			||||||
 | 
				
			|||||||
@ -157,14 +157,32 @@ class HelpController extends Controller
 | 
				
			|||||||
            $files = scandir($controllerPath);
 | 
					            $files = scandir($controllerPath);
 | 
				
			||||||
            foreach ($files as $file) {
 | 
					            foreach ($files as $file) {
 | 
				
			||||||
                if (strcmp(substr($file, -14), 'Controller.php') === 0) {
 | 
					                if (strcmp(substr($file, -14), 'Controller.php') === 0) {
 | 
				
			||||||
 | 
					                    $controllerClass = $module->controllerNamespace . '\\' . substr(basename($file), 0, -4);
 | 
				
			||||||
 | 
					                    if ($this->validateControllerClass($controllerClass)) {
 | 
				
			||||||
                        $commands[] = $prefix . Inflector::camel2id(substr(basename($file), 0, -14));
 | 
					                        $commands[] = $prefix . Inflector::camel2id(substr(basename($file), 0, -14));
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $commands;
 | 
					        return $commands;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 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.
 | 
					     * Displays all available commands.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
 | 
				
			|||||||
@ -19,6 +19,7 @@ require(__DIR__ . '/Yii.php');
 | 
				
			|||||||
$application = new yii\console\Application([
 | 
					$application = new yii\console\Application([
 | 
				
			||||||
    'id' => 'yii-console',
 | 
					    'id' => 'yii-console',
 | 
				
			||||||
    'basePath' => __DIR__ . '/console',
 | 
					    'basePath' => __DIR__ . '/console',
 | 
				
			||||||
 | 
					    'controllerNamespace' => 'yii\console\controllers',
 | 
				
			||||||
]);
 | 
					]);
 | 
				
			||||||
$exitCode = $application->run();
 | 
					$exitCode = $application->run();
 | 
				
			||||||
exit($exitCode);
 | 
					exit($exitCode);
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user