完善console

This commit is contained in:
yunwuxin
2016-03-23 14:46:48 +08:00
parent c32dc86763
commit 64406710ff

View File

@@ -9,12 +9,8 @@
namespace think; namespace think;
use think\console\command\Build as BuildCommand;
use think\console\command\Command; use think\console\command\Command;
use think\console\command\Help as HelpCommand; 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\Debug as DebugFormatterHelper;
use think\console\helper\Formatter as FormatterHelper; use think\console\helper\Formatter as FormatterHelper;
use think\console\helper\Process as ProcessHelper; use think\console\helper\Process as ProcessHelper;
@@ -48,6 +44,14 @@ class Console
private $terminalDimensions; private $terminalDimensions;
private $defaultCommand; 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') public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
{ {
$this->name = $name; $this->name = $name;
@@ -723,13 +727,20 @@ class Console
*/ */
protected function getDefaultCommands() protected function getDefaultCommands()
{ {
return [ $defaultCommands = [];
new HelpCommand(),
new ListCommand(), foreach (self::$defaultCommands as $classname) {
new MakeControllerCommand(), if (class_exists($classname) && is_subclass_of($classname, "think\\console\\command\\Command")) {
new MakeModelCommand(), $defaultCommands[] = new $classname();
new BuildCommand(), }
]; }
return $defaultCommands;
}
public static function addDefaultCommands(array $classnames)
{
self::$defaultCommands[] = array_merge(self::$defaultCommands, $classnames);
} }
/** /**