From 64406710ff402fe90e8585488b2db0004ecc585e Mon Sep 17 00:00:00 2001 From: yunwuxin <448901948@qq.com> Date: Wed, 23 Mar 2016 14:46:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84console?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Console.php | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/library/think/Console.php b/library/think/Console.php index 63ca114a..5035958a 100644 --- a/library/think/Console.php +++ b/library/think/Console.php @@ -9,12 +9,8 @@ namespace think; -use think\console\command\Build as BuildCommand; use think\console\command\Command; use think\console\command\Help as HelpCommand; -use think\console\command\Lists as ListCommand; -use think\console\command\make\Controller as MakeControllerCommand; -use think\console\command\make\Model as MakeModelCommand; use think\console\helper\Debug as DebugFormatterHelper; use think\console\helper\Formatter as FormatterHelper; use think\console\helper\Process as ProcessHelper; @@ -48,6 +44,14 @@ class Console private $terminalDimensions; private $defaultCommand; + private static $defaultCommands = [ + "think\\console\\command\\Help", + "think\\console\\command\\Lists", + "think\\console\\command\\Build", + "think\\console\\command\\make\\Controller", + "think\\console\\command\\make\\Model" + ]; + public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN') { $this->name = $name; @@ -723,13 +727,20 @@ class Console */ protected function getDefaultCommands() { - return [ - new HelpCommand(), - new ListCommand(), - new MakeControllerCommand(), - new MakeModelCommand(), - new BuildCommand(), - ]; + $defaultCommands = []; + + foreach (self::$defaultCommands as $classname) { + if (class_exists($classname) && is_subclass_of($classname, "think\\console\\command\\Command")) { + $defaultCommands[] = new $classname(); + } + } + + return $defaultCommands; + } + + public static function addDefaultCommands(array $classnames) + { + self::$defaultCommands[] = array_merge(self::$defaultCommands, $classnames); } /**