新增快速创建模块表格文件命令
This commit is contained in:
parent
f520d20574
commit
4580815fca
107
extend/catcher/command/Tools/CreateTableCommand.php
Normal file
107
extend/catcher/command/Tools/CreateTableCommand.php
Normal file
@ -0,0 +1,107 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace catcher\command\Tools;
|
||||
|
||||
use catchAdmin\system\model\SensitiveWord;
|
||||
use catcher\CatchAdmin;
|
||||
use catcher\facade\FileSystem;
|
||||
use catcher\library\Trie;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
|
||||
class CreateTableCommand extends Command
|
||||
{
|
||||
protected $table;
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
// 指令配置
|
||||
$this->setName('create:table')
|
||||
->addArgument('module', Argument::REQUIRED, 'module name')
|
||||
->addArgument('table', Argument::REQUIRED, 'table name')
|
||||
->addOption('form', '-f', Option::VALUE_NONE, '是否需要 form')
|
||||
->setDescription('cache sensitive word');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$module = $input->getArgument('module');
|
||||
$table = $input->getArgument('table');
|
||||
|
||||
$form = $input->getOption('form');
|
||||
|
||||
FileSystem::put(
|
||||
CatchAdmin::moduleDirectory($module) . 'tables' . DIRECTORY_SEPARATOR . (ucwords($table) . '.php'),
|
||||
$this->tableTemp($module, ucwords($table), $form)
|
||||
);
|
||||
|
||||
if (! $form) {
|
||||
FileSystem::put(
|
||||
CatchAdmin::moduleDirectory($module) .
|
||||
'tables' . DIRECTORY_SEPARATOR . 'forms' . DIRECTORY_SEPARATOR
|
||||
. (ucwords($table) . '.php'),
|
||||
$this->formTemp($module, ucwords($table))
|
||||
);
|
||||
}
|
||||
|
||||
$output->info('created success~');
|
||||
}
|
||||
|
||||
|
||||
protected function tableTemp($module, $table, $form)
|
||||
{
|
||||
$formTemp = ! $form ? sprintf('Factory::create(\'%s\');', $table) : '[];';
|
||||
|
||||
|
||||
return <<<PHP
|
||||
<?php
|
||||
namespace catchAdmin\\{$module}\\tables;
|
||||
|
||||
use catcher\CatchTable;
|
||||
use catchAdmin\\{$module}\\tables\\forms\\Factory;
|
||||
|
||||
class {$table} extends CatchTable
|
||||
{
|
||||
public function table()
|
||||
{
|
||||
// TODO: Implement table() method.
|
||||
return \$this->getTable('{$table}');
|
||||
}
|
||||
|
||||
protected function form()
|
||||
{
|
||||
// TODO: Implement form() method.
|
||||
return {$formTemp}
|
||||
}
|
||||
|
||||
}
|
||||
PHP;
|
||||
|
||||
}
|
||||
|
||||
protected function formTemp($module, $table)
|
||||
{
|
||||
return <<<PHP
|
||||
<?php
|
||||
namespace catchAdmin\\{$module}\\tables\\forms;
|
||||
|
||||
use catcher\\library\\form\\Form;
|
||||
|
||||
class {$table} extends Form
|
||||
{
|
||||
public function fields(): array
|
||||
{
|
||||
// TODO: Implement fields() method.
|
||||
return [
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
PHP;
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user