mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
改进make指令
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace think\console\command;
|
namespace think\console\command;
|
||||||
|
|
||||||
|
use think\App;
|
||||||
use think\console\Input;
|
use think\console\Input;
|
||||||
use think\console\input\Argument;
|
use think\console\input\Argument;
|
||||||
use think\console\input\Option;
|
use think\console\input\Option;
|
||||||
@@ -27,7 +28,7 @@ class Make extends Command
|
|||||||
$this
|
$this
|
||||||
->setName('make')
|
->setName('make')
|
||||||
->setDescription('Create a new applcation class')
|
->setDescription('Create a new applcation class')
|
||||||
->addArgument('namespace', Argument::OPTIONAL, null)
|
->addArgument('namespace', Argument::REQUIRED)
|
||||||
->addOption('layer', 'l', Option::VALUE_OPTIONAL, 'Layer Name', null)
|
->addOption('layer', 'l', Option::VALUE_OPTIONAL, 'Layer Name', null)
|
||||||
->addOption('extend', 'e', Option::VALUE_OPTIONAL, 'Extend Base class', null);
|
->addOption('extend', 'e', Option::VALUE_OPTIONAL, 'Extend Base class', null);
|
||||||
}
|
}
|
||||||
@@ -61,7 +62,7 @@ class Make extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 生成类库文件
|
// 生成类库文件
|
||||||
protected function build($namespace, $extend)
|
protected function build($namespace, $extend, $content = '')
|
||||||
{
|
{
|
||||||
$tpl = file_get_contents(THINK_PATH . 'tpl' . DS . 'make.tpl');
|
$tpl = file_get_contents(THINK_PATH . 'tpl' . DS . 'make.tpl');
|
||||||
|
|
||||||
@@ -73,8 +74,8 @@ class Make extends Command
|
|||||||
$extend = 'extends \\' . ltrim($extend, '\\');
|
$extend = 'extends \\' . ltrim($extend, '\\');
|
||||||
}
|
}
|
||||||
// 处理内容
|
// 处理内容
|
||||||
$content = str_replace(['{%extend%}', '{%className%}', '{%namespace%}'],
|
$content = str_replace(['{%extend%}', '{%className%}', '{%namespace%}', '{%content%}'],
|
||||||
[$extend, $className, implode('\\', $namespace)],
|
[$extend, $className, implode('\\', $namespace), $content],
|
||||||
$tpl);
|
$tpl);
|
||||||
|
|
||||||
// 处理文件名
|
// 处理文件名
|
||||||
@@ -86,7 +87,7 @@ class Make extends Command
|
|||||||
return realpath($file);
|
return realpath($file);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getResult($layer, $namespace, $module, $extend)
|
protected function getResult($layer, $namespace, $module, $extend, $content = '')
|
||||||
{
|
{
|
||||||
|
|
||||||
// 处理命名空间
|
// 处理命名空间
|
||||||
@@ -116,6 +117,6 @@ class Make extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->build($namespace, $extend);
|
return $this->build($namespace, $extend, $content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class Controller extends \think\console\command\Make
|
|||||||
$this
|
$this
|
||||||
->setName('make:controller')
|
->setName('make:controller')
|
||||||
->setDescription('Create a new controller class')
|
->setDescription('Create a new controller class')
|
||||||
->addArgument('namespace', Argument::OPTIONAL, null)
|
->addArgument('namespace', Argument::REQUIRED)
|
||||||
->addOption('module', 'm', Option::VALUE_OPTIONAL, 'Module Name', null)
|
->addOption('module', 'm', Option::VALUE_OPTIONAL, 'Module Name', null)
|
||||||
->addOption('extend', 'e', Option::VALUE_OPTIONAL, 'Base on Controller class', null);
|
->addOption('extend', 'e', Option::VALUE_OPTIONAL, 'Base on Controller class', null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class Model extends \think\console\command\Make
|
|||||||
$this
|
$this
|
||||||
->setName('make:model')
|
->setName('make:model')
|
||||||
->setDescription('Create a new model class')
|
->setDescription('Create a new model class')
|
||||||
->addArgument('namespace', Argument::OPTIONAL, null)
|
->addArgument('namespace', Argument::REQUIRED)
|
||||||
->addOption('module', 'm', Option::VALUE_OPTIONAL, 'Module Name', null)
|
->addOption('module', 'm', Option::VALUE_OPTIONAL, 'Module Name', null)
|
||||||
->addOption('extend', 'e', Option::VALUE_OPTIONAL, 'Base on Model class', null);
|
->addOption('extend', 'e', Option::VALUE_OPTIONAL, 'Base on Model class', null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,5 +13,5 @@ namespace {%namespace%};
|
|||||||
|
|
||||||
class {%className%} {%extend%}
|
class {%className%} {%extend%}
|
||||||
{
|
{
|
||||||
|
{%content%}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user