initialize module part

This commit is contained in:
Manuel Raynaud
2013-07-11 10:28:58 +02:00
parent 0c1c4b1822
commit 945a97ae78
8 changed files with 241 additions and 4 deletions

8
composer.lock generated
View File

@@ -206,12 +206,12 @@
"source": {
"type": "git",
"url": "https://github.com/propelorm/Propel2.git",
"reference": "1781303780ee496eadebedcb8c4636e728b6ea65"
"reference": "4cf5fca150ed93b33dc54206e3d9d943d0712621"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/propelorm/Propel2/zipball/1781303780ee496eadebedcb8c4636e728b6ea65",
"reference": "1781303780ee496eadebedcb8c4636e728b6ea65",
"url": "https://api.github.com/repos/propelorm/Propel2/zipball/4cf5fca150ed93b33dc54206e3d9d943d0712621",
"reference": "4cf5fca150ed93b33dc54206e3d9d943d0712621",
"shasum": ""
},
"require": {
@@ -258,7 +258,7 @@
"orm",
"persistence"
],
"time": "2013-07-05 09:02:18"
"time": "2013-07-10 11:32:06"
},
{
"name": "psr/log",

View File

@@ -0,0 +1,114 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
class ModuleGenerateCommand extends ContainerAwareCommand {
protected $module;
protected $moduleDirectory;
private $reservedKeyWords = array(
"thelia"
);
private $neededDirectories = array(
"Config",
"Model",
"Loop"
);
protected function configure()
{
$this
->setName("module:generate")
->setDescription("generate all needed files for creating a new Module")
->addArgument(
"name" ,
InputArgument::REQUIRED,
"name wanted for your Module"
)
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->module = $this->formatModuleName($input->getArgument("name"));
$this->moduleDirectory = THELIA_MODULE_DIR . DIRECTORY_SEPARATOR . $this->module;
$this->verifyExistingModule();
$this->createDirectories();
$this->createFiles();
}
private function createDirectories()
{
$fs = new Filesystem();
$fs->mkdir($this->moduleDirectory);
foreach ($this->neededDirectories as $directory) {
$fs->mkdir($this->moduleDirectory . DIRECTORY_SEPARATOR . $directory);
}
}
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 . "plugin.xml", $this->moduleDirectory . DIRECTORY_SEPARATOR . "Config" . DIRECTORY_SEPARATOR . "plugin.xml");
$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);
file_put_contents($this->moduleDirectory . DIRECTORY_SEPARATOR . "Config". DIRECTORY_SEPARATOR . "schema.xml", $schemaContent);
}
private function verifyExistingModule()
{
if (file_exists($this->moduleDirectory)) {
throw new \RuntimeException(sprintf("%s module already exists", $this->module));
}
}
private function formatModuleName($name)
{
return ucfirst($name);
}
}

View File

@@ -0,0 +1,36 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace %%NAMESPACE%%;
use Thelia\Module\BaseModule;
class %%CLASSNAME%% extends BaseModule
{
/**
* YOU HAVE TO IMPLEMENT HERE ABSTRACT METHODD FROM BaseModule Class
* Like install and destroy
*/
}

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8" ?>
<config xmlns="http://thelia.net/schema/dic/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd">
<loops>
<!-- sample definition
<loop name="MySuperLoop" class="MyModule\Loop\MySuperLoop" />
-->
</loops>
<forms>
<!--
<form name="MyFormName" class="MyModule\Form\MySuperForm" />
-->
</forms>
<commands>
<!--
<command class="MyModule\Command\MySuperCommand" />
-->
</commands>
<templateDirectives>
<!-- Sample definition
<templateDirectives class="MyModule\Directive\MyTemplateDirective" name="my_filter"/>
-->
</templateDirectives>
<!--
<services>
</services>
-->
</config>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<database defaultIdMethod="native" name="propel">
<!--
See propel documentation on http://propelorm.org for all information about schema file
-->
<external-schema filename="%%CONFIG_DIR%%schema.xml" referenceOnly="true" />
</database>

View File

@@ -34,6 +34,7 @@
<commands>
<command class="Thelia\Command\CacheClear"/>
<command class="Thelia\Command\Install"/>
<command class="Thelia\Command\ModuleGenerateCommand"/>
</commands>
<services>

View File

@@ -0,0 +1,43 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Module;
abstract class BaseModule
{
public function __construct()
{
}
protected function activate()
{
}
abstract public function install();
abstract public function destroy();
}