Improved module generation command

This commit is contained in:
Franck Allimant
2014-03-24 16:47:37 +01:00
parent 4311d6c10f
commit 446c2e5438
5 changed files with 65 additions and 0 deletions

View File

@@ -42,6 +42,10 @@ abstract class BaseModuleGenerate extends ContainerAwareCommand
'Config',
'Model',
'Loop',
'Command',
'Controller',
'EventListeners',
'I18n',
'AdminIncludes',
'templates',
);

View File

@@ -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);

View File

@@ -0,0 +1,4 @@
<?php
return array(
// 'an english string' => 'The displayed english string',
);

View File

@@ -0,0 +1,4 @@
<?php
return array(
// 'an english string' => 'La traduction française de la chaine',
);

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
<!--
if a /admin/module/%%CLASSNAME_LOWER%%/ route is provided, a "Configuration" button will be displayed
for the module in the module list. Clicking this button will invoke this route.
<route id="my_route_id" path="/admin/module/%%CLASSNAME_LOWER%%">
<default key="_controller">%%NAMESPACE%%\Full\Class\Name\Of\YourConfigurationController::methodName</default>
</route>
<route id="my_route_id" path="/admin/module/%%CLASSNAME_LOWER%%/route-name">
<default key="_controller">%%NAMESPACE%%\Full\Class\Name\Of\YourAdminController::methodName</default>
</route>
<route id="my_route_id" path="/my/route/name">
<default key="_controller">%%NAMESPACE%%\Full\Class\Name\Of\YourOtherController::methodName</default>
</route>
...add as many routes as required.
<route>
...
</route>
-->
</routes>