diff --git a/extend/catcher/command/CreateModuleCommand.php b/extend/catcher/command/CreateModuleCommand.php new file mode 100644 index 0000000..02d118e --- /dev/null +++ b/extend/catcher/command/CreateModuleCommand.php @@ -0,0 +1,131 @@ +setName('module:create') + ->addArgument('module', Argument::REQUIRED, 'module name') + ->setDescription('create module service'); + } + + protected function execute(Input $input, Output $output) + { + $this->module = strtolower($input->getArgument('module')); + + $this->moduleDir = CatchAdmin::moduleDirectory($this->module); + + $this->namespaces = CatchAdmin::NAME . '\\\\' . $this->module . '\\\\'; + + $this->createController(); + $this->createRequest(); + $this->createModel(); + // $this->createService(); + $this->createView(); + $this->createValidate(); + $this->createRoute(); + $this->moduleJson(); + + $output->warning('module created'); + } + + + protected function createController() + { + mkdir($this->moduleDir . 'controller' . DIRECTORY_SEPARATOR); + return file_put_contents($this->moduleDir . 'controller' . DIRECTORY_SEPARATOR . 'Index.php', str_replace( + ['{CLASS}', '{NAMESPACE}', '{MODULE}'], + ['Index', $this->namespaces . 'controller', $this->module], + file_get_contents(__DIR__ . DIRECTORY_SEPARATOR .'stubs'.DIRECTORY_SEPARATOR. 'controller.stub') + )); + } + + + protected function createModel() + { + + } + + protected function createView() + { + mkdir($this->moduleDir . DIRECTORY_SEPARATOR . 'view'); + + file_put_contents($this->moduleDir . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'index.html', ''); + file_put_contents($this->moduleDir . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'create.html', ''); + file_put_contents($this->moduleDir . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'edit.html', ''); + } + + protected function createValidate() + { + $validatePath = $this->moduleDir . DIRECTORY_SEPARATOR . 'validate' . DIRECTORY_SEPARATOR; + mkdir($validatePath); + file_put_contents($validatePath . 'CreateValidate.php', str_replace( + ['{Namespace}', '{Class}'], + [$this->namespaces . 'validate', 'Create'], + file_get_contents(__DIR__ . 'stubs' . DIRECTORY_SEPARATOR . 'validate.stub'))); + + file_put_contents($validatePath . 'UpdateValidate.php', str_replace( + ['{Namespace}', '{Class}'], + [$this->namespaces . 'validate', 'Update'], + file_get_contents(__DIR__ . 'stubs' . DIRECTORY_SEPARATOR . 'validate.stub'))); + } + + protected function createRequest() + { + $requestPath = $this->moduleDir . DIRECTORY_SEPARATOR . 'request' . DIRECTORY_SEPARATOR; + mkdir($requestPath); + file_put_contents($validatePath . 'CreateRequest.php', str_replace( + ['{Namespace}', '{Class}'], + [$this->namespaces . 'request', 'Create'], + file_get_contents(__DIR__ . 'stubs' . DIRECTORY_SEPARATOR . 'request.stub'))); + + file_put_contents($validatePath . 'UpdateRequest.php', str_replace( + ['{Namespace}', '{Class}'], + [$this->namespaces . 'request', 'Update'], + file_get_contents(__DIR__ . 'stubs' . DIRECTORY_SEPARATOR . 'request.stub'))); + } + + protected function database() + { + mkdir($this->moduleDir . DIRECTORY_SEPARATOR . 'database'); + mkdir($this->moduleDir . DIRECTORY_SEPARATOR . 'database'.DIRECTORY_SEPARATOR.'migrations'); + mkdir($this->moduleDir . DIRECTORY_SEPARATOR . 'database'.DIRECTORY_SEPARATOR . 'seeds'); + } + + protected function moduleJson() + { + file_put_contents($this->moduleDir.DIRECTORY_SEPARATOR .'module.json', str_replace( + ['{MODULE}', '{SERVICE}'], + [$this->module, $this->namespaces. ucfirst($this->module) . 'Service'], + file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'module.stub'))); + } + + protected function createRoute() + { + file_put_contents($this->moduleDir.DIRECTORY_SEPARATOR .'route.php', + file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'route.stub')); + } + + protected function createService() + { + file_put_contents($this->moduleDir.DIRECTORY_SEPARATOR . ucfirst($this->module) . 'Service.php', str_replace( + ['{CLASS}', '{NAMESPACE}'], + [ucfirst($this->module), $this->namespaces . '\\' . $this->module], + file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'provider.stub'))); + } + + +} diff --git a/extend/catcher/command/InstallCommand.php b/extend/catcher/command/InstallCommand.php index f8d5212..785cbe5 100644 --- a/extend/catcher/command/InstallCommand.php +++ b/extend/catcher/command/InstallCommand.php @@ -316,8 +316,9 @@ class InstallCommand extends Command | / /__/ /_/ / /_/ /__/ / / / / ___ / /_/ / / / / / / / / / / | | \___/\__,_/\__/\___/_/ /_/ /_/ |_\__,_/_/ /_/ /_/_/_/ /_/ | | | - \ __ __ __ __ _ __ _ __ enjoy it ! _ __ __ __ __ __ __ ___ _ @ 2017 ~ %s - + \ __ __ __ __ _ __ _ __ enjoy it ! _ __ __ __ __ __ __ ___ _ @ 2017 ~ %s + 账号: admin@gmail.com + 密码: admin ', $year)); } diff --git a/extend/catcher/command/stubs/command.stub b/extend/catcher/command/stubs/command.stub new file mode 100644 index 0000000..367b248 --- /dev/null +++ b/extend/catcher/command/stubs/command.stub @@ -0,0 +1,21 @@ +setName('') + ->setDescription(''); + } + + protected function execute(Input $input, Output $output) + { + } +} diff --git a/extend/catcher/command/stubs/controller.stub b/extend/catcher/command/stubs/controller.stub new file mode 100644 index 0000000..93e64c2 --- /dev/null +++ b/extend/catcher/command/stubs/controller.stub @@ -0,0 +1,35 @@ +fetch('{MODULE}::index'); + } + + public function create() + { + return $this->fetch('{MODULE}::create'); + } + + public function save() + {} + + public function read() + {} + + public function edit() + { + return $this->fetch('{MODULE}::edit'); + } + + public function update() + {} + + public function delete() + {} + +} \ No newline at end of file diff --git a/extend/catcher/command/stubs/event.stub b/extend/catcher/command/stubs/event.stub new file mode 100644 index 0000000..f6232f4 --- /dev/null +++ b/extend/catcher/command/stubs/event.stub @@ -0,0 +1,11 @@ +get('index', 'controller@method'); + diff --git a/extend/catcher/command/stubs/seeder.stub b/extend/catcher/command/stubs/seeder.stub new file mode 100644 index 0000000..6982f54 --- /dev/null +++ b/extend/catcher/command/stubs/seeder.stub @@ -0,0 +1,19 @@ +