A generated module works now out of the box (no need to update

module.xml)
This commit is contained in:
Franck Allimant
2014-01-16 11:25:09 +01:00
parent 380e856df8
commit b27fbd776f
2 changed files with 33 additions and 18 deletions

View File

@@ -84,23 +84,38 @@ class ModuleGenerateCommand extends BaseModuleGenerate
private function createFiles()
{
$fs = new Filesystem();
$skeletonDir = str_replace("/", DIRECTORY_SEPARATOR, THELIA_ROOT . "/core/lib/Thelia/Command/Skeleton/Module/");
$fs->copy($skeletonDir . "config.xml", $this->moduleDirectory . DIRECTORY_SEPARATOR . "Config" . DIRECTORY_SEPARATOR . "config.xml");
$fs->copy($skeletonDir . "module.xml", $this->moduleDirectory . DIRECTORY_SEPARATOR . "Config" . DIRECTORY_SEPARATOR . "module.xml");
$classContent = file_get_contents($skeletonDir . "Class.php");
try {
$skeletonDir = str_replace("/", DIRECTORY_SEPARATOR, THELIA_ROOT . "/core/lib/Thelia/Command/Skeleton/Module/");
$classContent = str_replace("%%CLASSNAME%%", $this->module, $classContent);
$classContent = str_replace("%%NAMESPACE%%", $this->module, $classContent);
$fs->copy($skeletonDir . "config.xml", $this->moduleDirectory . DIRECTORY_SEPARATOR . "Config" . DIRECTORY_SEPARATOR . "config.xml");
file_put_contents($this->moduleDirectory . DIRECTORY_SEPARATOR . $this->module.".php", $classContent);
$moduleContent = file_get_contents($skeletonDir . "module.xml");
$schemaContent = file_get_contents($skeletonDir . "schema.xml");
$moduleContent = str_replace("%%CLASSNAME%%", $this->module, $moduleContent);
$moduleContent = str_replace("%%NAMESPACE%%", $this->module, $moduleContent);
$schemaContent = str_replace("%%CONFIG_DIR%%", THELIA_CONF_DIR, $schemaContent);
$schemaContent = str_replace("%%NAMESPACE%%", $this->module, $schemaContent);
file_put_contents($this->moduleDirectory . DIRECTORY_SEPARATOR . "Config". DIRECTORY_SEPARATOR . "module.xml", $moduleContent);
file_put_contents($this->moduleDirectory . DIRECTORY_SEPARATOR . "Config". DIRECTORY_SEPARATOR . "schema.xml", $schemaContent);
$classContent = file_get_contents($skeletonDir . "Class.php");
$classContent = str_replace("%%CLASSNAME%%", $this->module, $classContent);
$classContent = str_replace("%%NAMESPACE%%", $this->module, $classContent);
file_put_contents($this->moduleDirectory . DIRECTORY_SEPARATOR . $this->module.".php", $classContent);
$schemaContent = file_get_contents($skeletonDir . "schema.xml");
$schemaContent = str_replace("%%CONFIG_DIR%%", THELIA_CONF_DIR, $schemaContent);
$schemaContent = str_replace("%%NAMESPACE%%", $this->module, $schemaContent);
file_put_contents($this->moduleDirectory . DIRECTORY_SEPARATOR . "Config". DIRECTORY_SEPARATOR . "schema.xml", $schemaContent);
}
catch (\Exception $ex) {
$fs->remove($this->moduleDirectory);
throw $ex;
}
}
}

View File

@@ -1,18 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<module>
<fullnamespace></fullnamespace>
<fullnamespace>%%NAMESPACE%%\%%CLASSNAME%%</fullnamespace>
<descriptive locale="en_US">
<title></title>
<title>Automatically generated module - please update module.xml file</title>
</descriptive>
<descriptive locale="fr_FR">
<title></title>
<title>Module généré autromatiquement - editez le fichier module.xml</title>
</descriptive>
<version></version>
<author>
<name></name>
<email></email>
</author>
<type></type>
<thelia></thelia>
<stability></stability>
</module>
<type>classic</type>
<thelia>2.0.0</thelia>
<stability>other</stability>
</module>