From 4580815fcaf8f414c5933c268be5157754afd25e Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Thu, 29 Apr 2021 08:47:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=BF=AB=E9=80=9F=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E6=A8=A1=E5=9D=97=E8=A1=A8=E6=A0=BC=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/Tools/CreateTableCommand.php | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 extend/catcher/command/Tools/CreateTableCommand.php diff --git a/extend/catcher/command/Tools/CreateTableCommand.php b/extend/catcher/command/Tools/CreateTableCommand.php new file mode 100644 index 0000000..2104885 --- /dev/null +++ b/extend/catcher/command/Tools/CreateTableCommand.php @@ -0,0 +1,107 @@ +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 <<getTable('{$table}'); + } + + protected function form() + { + // TODO: Implement form() method. + return {$formTemp} + } + +} +PHP; + + } + + protected function formTemp($module, $table) + { + return <<