Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions src/Builder/Component/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class Module extends AbstractComponent
*/
protected $variableValues = [];

public function setModuleDirectories($moduleDirectories)
{
$this->moduleDirectories = $moduleDirectories;
}

/**
* Module build
*
Expand Down Expand Up @@ -73,15 +78,16 @@ 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());

$this
->buildDirectories()
->getVariableValues()
->createConfig()
->createModule();
->createModule()
->createRoutes();

$this->notifySuccess(sprintf(
'Module "%s" was successfully created.',
Expand Down Expand Up @@ -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
*
Expand All @@ -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');
Expand Down
19 changes: 18 additions & 1 deletion src/Commands/Builtin/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]',

];
Expand All @@ -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();
}
Expand Down
9 changes: 9 additions & 0 deletions t/module/Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);

namespace @@FQMN@@;

class Module extends \BaseModule
{

}
12 changes: 12 additions & 0 deletions t/module/Routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
declare(strict_types=1);

namespace @@FQMN@@;

class Routes extends \BaseRoutes
{
public function __construct(\Phalcon\Mvc\Router $router, $module)
{
parent::__construct($router, $module);
}
}