From 446c2e5438741932b6af47878df66afbf9627594 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Mon, 24 Mar 2014 16:47:37 +0100 Subject: [PATCH] Improved module generation command --- .../lib/Thelia/Command/BaseModuleGenerate.php | 4 +++ .../Thelia/Command/ModuleGenerateCommand.php | 22 +++++++++++++ .../Command/Skeleton/Module/I18n/en_US.php | 4 +++ .../Command/Skeleton/Module/I18n/fr_FR.php | 4 +++ .../Command/Skeleton/Module/routing.xml | 31 +++++++++++++++++++ 5 files changed, 65 insertions(+) create mode 100644 core/lib/Thelia/Command/Skeleton/Module/I18n/en_US.php create mode 100644 core/lib/Thelia/Command/Skeleton/Module/I18n/fr_FR.php create mode 100644 core/lib/Thelia/Command/Skeleton/Module/routing.xml diff --git a/core/lib/Thelia/Command/BaseModuleGenerate.php b/core/lib/Thelia/Command/BaseModuleGenerate.php index b3286c874..10c0f9398 100644 --- a/core/lib/Thelia/Command/BaseModuleGenerate.php +++ b/core/lib/Thelia/Command/BaseModuleGenerate.php @@ -42,6 +42,10 @@ abstract class BaseModuleGenerate extends ContainerAwareCommand 'Config', 'Model', 'Loop', + 'Command', + 'Controller', + 'EventListeners', + 'I18n', 'AdminIncludes', 'templates', ); diff --git a/core/lib/Thelia/Command/ModuleGenerateCommand.php b/core/lib/Thelia/Command/ModuleGenerateCommand.php index 8a610b991..058d071c1 100644 --- a/core/lib/Thelia/Command/ModuleGenerateCommand.php +++ b/core/lib/Thelia/Command/ModuleGenerateCommand.php @@ -88,6 +88,7 @@ class ModuleGenerateCommand extends BaseModuleGenerate try { $skeletonDir = str_replace("/", DIRECTORY_SEPARATOR, THELIA_ROOT . "/core/lib/Thelia/Command/Skeleton/Module/"); + // config.xml file $fs->copy($skeletonDir . "config.xml", $this->moduleDirectory . DIRECTORY_SEPARATOR . "Config" . DIRECTORY_SEPARATOR . "config.xml"); $moduleContent = file_get_contents($skeletonDir . "module.xml"); @@ -97,6 +98,7 @@ class ModuleGenerateCommand extends BaseModuleGenerate file_put_contents($this->moduleDirectory . DIRECTORY_SEPARATOR . "Config". DIRECTORY_SEPARATOR . "module.xml", $moduleContent); + // PHP Class template $classContent = file_get_contents($skeletonDir . "Class.php.template"); $classContent = str_replace("%%CLASSNAME%%", $this->module, $classContent); @@ -104,11 +106,31 @@ class ModuleGenerateCommand extends BaseModuleGenerate file_put_contents($this->moduleDirectory . DIRECTORY_SEPARATOR . $this->module.".php", $classContent); + // schema.xml file $schemaContent = file_get_contents($skeletonDir . "schema.xml"); $schemaContent = str_replace("%%NAMESPACE%%", $this->module, $schemaContent); file_put_contents($this->moduleDirectory . DIRECTORY_SEPARATOR . "Config". DIRECTORY_SEPARATOR . "schema.xml", $schemaContent); + + // routing.xml file + $routingContent = file_get_contents($skeletonDir . "routing.xml"); + + $routingContent = str_replace("%%NAMESPACE%%", $this->module, $routingContent); + $routingContent = str_replace("%%CLASSNAME_LOWER%%", strtolower($this->module), $routingContent); + + file_put_contents($this->moduleDirectory . DIRECTORY_SEPARATOR . "Config". DIRECTORY_SEPARATOR . "routing.xml", $routingContent); + + // I18n sample files + $fs->copy( + $skeletonDir . DIRECTORY_SEPARATOR . "I18n" . DIRECTORY_SEPARATOR . "fr_FR.php", + $this->moduleDirectory . DIRECTORY_SEPARATOR . "I18n" . DIRECTORY_SEPARATOR . "fr_FR.php" + ); + + $fs->copy( + $skeletonDir . DIRECTORY_SEPARATOR . "I18n" . DIRECTORY_SEPARATOR . "en_US.php", + $this->moduleDirectory . DIRECTORY_SEPARATOR . "I18n" . DIRECTORY_SEPARATOR . "en_US.php" + ); } catch (\Exception $ex) { $fs->remove($this->moduleDirectory); diff --git a/core/lib/Thelia/Command/Skeleton/Module/I18n/en_US.php b/core/lib/Thelia/Command/Skeleton/Module/I18n/en_US.php new file mode 100644 index 000000000..f32e11983 --- /dev/null +++ b/core/lib/Thelia/Command/Skeleton/Module/I18n/en_US.php @@ -0,0 +1,4 @@ + 'The displayed english string', +); \ No newline at end of file diff --git a/core/lib/Thelia/Command/Skeleton/Module/I18n/fr_FR.php b/core/lib/Thelia/Command/Skeleton/Module/I18n/fr_FR.php new file mode 100644 index 000000000..fd88a21eb --- /dev/null +++ b/core/lib/Thelia/Command/Skeleton/Module/I18n/fr_FR.php @@ -0,0 +1,4 @@ + 'La traduction française de la chaine', +); \ No newline at end of file diff --git a/core/lib/Thelia/Command/Skeleton/Module/routing.xml b/core/lib/Thelia/Command/Skeleton/Module/routing.xml new file mode 100644 index 000000000..22d919792 --- /dev/null +++ b/core/lib/Thelia/Command/Skeleton/Module/routing.xml @@ -0,0 +1,31 @@ + + + + + + +