diff --git a/src/Builder/Component/Module.php b/src/Builder/Component/Module.php index 99ad9a1c0..5314ead56 100644 --- a/src/Builder/Component/Module.php +++ b/src/Builder/Component/Module.php @@ -37,6 +37,11 @@ class Module extends AbstractComponent */ protected $variableValues = []; + public function setModuleDirectories($moduleDirectories) + { + $this->moduleDirectories = $moduleDirectories; + } + /** * Module build * @@ -73,7 +78,7 @@ public function build(): void $modulesDir = $this->path->getRootPath($modulesDir); } - $this->options->offsetSet('modulesDir', $modulesDir); + $this->options->offsetSet('modulesDir', rtrim($modulesDir, '/\\')); $this->options->offsetSet('templatePath', realpath($templatePath)); $this->options->offsetSet('projectPath', $this->path->getRootPath()); @@ -81,7 +86,8 @@ public function build(): void ->buildDirectories() ->getVariableValues() ->createConfig() - ->createModule(); + ->createModule() + ->createRoutes(); $this->notifySuccess(sprintf( 'Module "%s" was successfully created.', @@ -248,6 +254,29 @@ private function createModule() return $this; } + /** + * Create Routes + * + * @return $this + */ + private function createRoutes() + { + $modulesDir = $this->options->get('modulesDir'); + $moduleName = $this->options->get('name'); + $namespace = $this->options->get('namespace'); + + $getFile = $this->options->get('templatePath') . DIRECTORY_SEPARATOR . 'Routes.php'; + $putFile = $modulesDir . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'Routes.php'; + + if (!file_exists($getFile)) { + return $this; + } + + $this->generateFile($getFile, $putFile, $moduleName, $namespace); + + return $this; + } + /** * Creates the configuration * @@ -256,6 +285,9 @@ private function createModule() private function createConfig() { $type = $this->options->get('config-type', 'php'); + if ($type === 'none') { + return $this; + } $modulesDir = $this->options->get('modulesDir'); $moduleName = $this->options->get('name'); $namespace = $this->options->get('namespace'); diff --git a/src/Commands/Builtin/Module.php b/src/Commands/Builtin/Module.php index fc9f306bd..a29e2c591 100644 --- a/src/Commands/Builtin/Module.php +++ b/src/Commands/Builtin/Module.php @@ -37,6 +37,10 @@ public function getPossibleParams(): array 'output=s' => 'Folder where modules are located [optional]', 'config-type=s' => 'The config type to be generated (ini, json, php, yaml) [optional]', 'template-path=s' => 'Specify a template path [optional]', + 'module-config-path=s' => 'Specify a config directory path inside the module [optional]', + 'module-controllers-path=s' => 'Specify a controllers directory path inside the module [optional]', + 'module-models-path=s' => 'Specify a models directory path inside the module [optional]', + 'module-views-path=s' => 'Specify a views directory path inside the module [optional]', 'help' => 'Shows this help [optional]', ]; @@ -55,14 +59,27 @@ public function run(array $parameters): void $configType = $this->getOption('config-type', null, 'php'); $modulesDir = $this->getOption('output'); $templatePath = $this->getOption('template-path', null, TEMPLATE_PATH . DIRECTORY_SEPARATOR . 'module'); + $moduleConfigPath = $this->getOption('module-config-path', null, 'config'); + $moduleControllersPath = $this->getOption('module-controllers-path', null, 'controllers'); + $moduleModelsPath = $this->getOption('module-models-path', null, 'models'); + $moduleViewsPath = $this->getOption('module-views-path', null, 'views'); $builder = new ModuleBuilder([ 'name' => $moduleName, 'namespace' => $namespace, 'config-type' => $configType, 'templatePath' => $templatePath, - 'modulesDir' => $modulesDir + 'modulesDir' => $modulesDir, + 'moduleConfigPath' => $moduleConfigPath, + 'moduleControllersPath' => $moduleControllersPath, + 'moduleModelsPath' => $moduleModelsPath, + 'moduleViewsPath' => $moduleViewsPath, ]); + $moduleDirectories = [$moduleControllersPath, $moduleModelsPath, $moduleViewsPath]; + if ($configType !== 'none') { + $moduleDirectories[] = $moduleConfigPath; + } + $builder->setModuleDirectories($moduleDirectories); $builder->build(); } diff --git a/t/module/Module.php b/t/module/Module.php new file mode 100644 index 000000000..1d89a1ff9 --- /dev/null +++ b/t/module/Module.php @@ -0,0 +1,9 @@ +