change phpdoc api generator to phpdoc
This commit is contained in:
58
documentation/api/files/Command/BaseModuleGenerate.php.txt
Normal file
58
documentation/api/files/Command/BaseModuleGenerate.php.txt
Normal file
@@ -0,0 +1,58 @@
|
||||
<?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 Propel\Runtime\Propel;
|
||||
use Symfony\Component\Console\Application;
|
||||
|
||||
|
||||
abstract class BaseModuleGenerate extends ContainerAwareCommand {
|
||||
|
||||
protected $module;
|
||||
protected $moduleDirectory;
|
||||
|
||||
protected $reservedKeyWords = array(
|
||||
"thelia"
|
||||
);
|
||||
|
||||
protected $neededDirectories = array(
|
||||
"Config",
|
||||
"Model",
|
||||
"Loop"
|
||||
);
|
||||
|
||||
protected function verifyExistingModule()
|
||||
{
|
||||
if (file_exists($this->moduleDirectory)) {
|
||||
throw new \RuntimeException(sprintf("%s module already exists", $this->module));
|
||||
}
|
||||
}
|
||||
|
||||
protected function formatModuleName($name)
|
||||
{
|
||||
if (in_array(strtolower($name), $this->reservedKeyWords)) {
|
||||
throw new \RuntimeException(sprintf("%s module name is a reserved keyword", $name));
|
||||
}
|
||||
return ucfirst($name);
|
||||
}
|
||||
}
|
||||
64
documentation/api/files/Command/CacheClear.php.txt
Normal file
64
documentation/api/files/Command/CacheClear.php.txt
Normal file
@@ -0,0 +1,64 @@
|
||||
<?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;
|
||||
use Symfony\Component\Filesystem\Exception\IOException;
|
||||
|
||||
use Thelia\Command\ContainerAwareCommand;
|
||||
|
||||
class CacheClear extends ContainerAwareCommand
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName("cache:clear")
|
||||
->setDescription("Invalidate all caches");
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
|
||||
$cacheDir = $this->getContainer()->getParameter("kernel.cache_dir");
|
||||
|
||||
if (!is_writable($cacheDir)) {
|
||||
throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $cacheDir));
|
||||
}
|
||||
|
||||
$output->writeln(sprintf("Clearing cache in <info>%s</info> directory", $cacheDir));
|
||||
|
||||
$fs = new Filesystem();
|
||||
try {
|
||||
$fs->remove($cacheDir);
|
||||
|
||||
$output->writeln("<info>cache cleared successfully</info>");
|
||||
} catch(IOException $e) {
|
||||
$output->writeln(sprintf("error during clearing cache : %s", $e->getMessage()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?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\Command\Command;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
|
||||
/**
|
||||
* Command.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class ContainerAwareCommand extends Command implements ContainerAwareInterface {
|
||||
/**
|
||||
* @var ContainerInterface
|
||||
*/
|
||||
private $container;
|
||||
|
||||
/**
|
||||
* @return ContainerInterface
|
||||
*/
|
||||
protected function getContainer()
|
||||
{
|
||||
if (null === $this->container) {
|
||||
$this->container = $this->getApplication()->getKernel()->getContainer();
|
||||
}
|
||||
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ContainerAwareInterface::setContainer()
|
||||
*/
|
||||
public function setContainer(ContainerInterface $container = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
}
|
||||
366
documentation/api/files/Command/Install.php.txt
Normal file
366
documentation/api/files/Command/Install.php.txt
Normal file
@@ -0,0 +1,366 @@
|
||||
<?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\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Thelia\Command\ContainerAwareCommand;
|
||||
|
||||
|
||||
class Install extends ContainerAwareCommand
|
||||
{
|
||||
/**
|
||||
* Configure the command
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName("thelia:install")
|
||||
->setDescription("Install thelia using cli tools. For now Thelia only use mysql database")
|
||||
->setHelp("The <info>thelia:install</info> command install Thelia database and create config file needed.")
|
||||
->addOption(
|
||||
"db_host",
|
||||
null,
|
||||
InputOption::VALUE_OPTIONAL,
|
||||
"host for your database"
|
||||
)
|
||||
->addOption(
|
||||
"db_username",
|
||||
null,
|
||||
InputOption::VALUE_OPTIONAL,
|
||||
"username for your database"
|
||||
)
|
||||
->addOption(
|
||||
"db_password",
|
||||
null,
|
||||
InputOption::VALUE_OPTIONAL,
|
||||
"password for your database"
|
||||
)
|
||||
->addOption(
|
||||
"db_name",
|
||||
null,
|
||||
InputOption::VALUE_OPTIONAL,
|
||||
"database name"
|
||||
)
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$output->writeln(array(
|
||||
'',
|
||||
'Welcome to Thelia install process',
|
||||
'You need information about your database configuration (host, username, password, database name, etc)',
|
||||
''
|
||||
));
|
||||
|
||||
$this->checkPermission($output);
|
||||
|
||||
|
||||
$connectionInfo = array(
|
||||
"host" => $input->getOption("db_host"),
|
||||
"dbName" => $input->getOption("db_name"),
|
||||
"username" => $input->getOption("db_username"),
|
||||
"password" => $input->getOption("db_password")
|
||||
);
|
||||
|
||||
|
||||
|
||||
while(false === $connection = $this->tryConnection($connectionInfo, $output)) {
|
||||
$connectionInfo = $this->getConnectionInfo($input, $output);
|
||||
}
|
||||
|
||||
$this->createDatabase($connection, $connectionInfo["dbName"]);
|
||||
|
||||
$output->writeln(array(
|
||||
"",
|
||||
"<info>Creating Thelia database, please wait</info>",
|
||||
""
|
||||
));
|
||||
$this->insertSql($connection, $connectionInfo["dbName"]);
|
||||
|
||||
$output->writeln(array(
|
||||
"",
|
||||
"<info>Database created without errors</info>",
|
||||
"<info>Creating file configuration, please wait</info>",
|
||||
""
|
||||
));
|
||||
|
||||
$this->createConfigFile($connectionInfo);
|
||||
|
||||
$output->writeln(array(
|
||||
"",
|
||||
"<info>Config file created with success. Your thelia is installed</info>",
|
||||
""
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if needed directories have write permission
|
||||
*
|
||||
* @param \Symfony\Component\Console\Output\OutputInterface $output
|
||||
*/
|
||||
protected function checkPermission(OutputInterface $output)
|
||||
{
|
||||
$output->writeln(array(
|
||||
"Checking some permissions"
|
||||
));
|
||||
|
||||
$confDir = THELIA_ROOT . "local/config";
|
||||
$cacheDir = THELIA_ROOT . "cache";
|
||||
$logDir = THELIA_ROOT . "log";
|
||||
|
||||
$conf = is_writable($confDir);
|
||||
$cache = is_writable($cacheDir);
|
||||
$log = is_writable($logDir);
|
||||
|
||||
$output->writeln(array(
|
||||
sprintf(
|
||||
"<info>config directory(%s)...</info> %s",
|
||||
$confDir,
|
||||
$conf ? "<info>Ok</info>" : "<error>Fail</error>"
|
||||
),
|
||||
sprintf(
|
||||
"<info>cache directory(%s)...</info> %s"
|
||||
,$cacheDir,
|
||||
$cache ? "<info>Ok</info>" : "<error>Fail</error>"
|
||||
),
|
||||
sprintf(
|
||||
"<info>log directory(%s)...</info> %s",
|
||||
$logDir,
|
||||
$log ? "<info>Ok</info>" : "<error>Fail</error>"
|
||||
),
|
||||
));
|
||||
|
||||
if ($conf === false || $cache === false || $log === false) {
|
||||
$output->writeln(array(
|
||||
"",
|
||||
"<error>Please put correct permission and reload install process</error>"
|
||||
));
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* rename database config file and complete it
|
||||
*
|
||||
* @param array $connectionInfo
|
||||
*/
|
||||
protected function createConfigFile($connectionInfo)
|
||||
{
|
||||
$fs = new Filesystem();
|
||||
|
||||
$sampleConfigFile = THELIA_ROOT . "/local/config/database.yml.sample";
|
||||
$configFile = THELIA_ROOT . "/local/config/database.yml";
|
||||
|
||||
|
||||
$fs->copy($sampleConfigFile, $configFile, true);
|
||||
|
||||
$configContent = file_get_contents($configFile);
|
||||
|
||||
$configContent = str_replace("%DRIVER%", "mysql", $configContent);
|
||||
$configContent = str_replace("%USERNAME%", $connectionInfo["username"], $configContent);
|
||||
$configContent = str_replace("%PASSWORD%", $connectionInfo["password"], $configContent);
|
||||
$configContent = str_replace(
|
||||
"%DSN%",
|
||||
sprintf("mysql:host=%s;dbname=%s", $connectionInfo["host"], $connectionInfo["dbName"]),
|
||||
$configContent
|
||||
);
|
||||
|
||||
file_put_contents($configFile, $configContent);
|
||||
|
||||
$fs->remove($sampleConfigFile);
|
||||
|
||||
$fs->remove($this->getContainer()->getParameter("kernel.cache_dir"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert all sql needed in database
|
||||
*
|
||||
* @param \PDO $connection
|
||||
* @param $dbName
|
||||
*/
|
||||
protected function insertSql(\PDO $connection, $dbName)
|
||||
{
|
||||
$connection->query(sprintf("use %s", $dbName));
|
||||
$sql = array();
|
||||
$sql = array_merge(
|
||||
$sql,
|
||||
$this->prepareSql(file_get_contents(THELIA_ROOT . "/install/thelia.sql")),
|
||||
$this->prepareSql(file_get_contents(THELIA_ROOT . "/install/insert.sql"))
|
||||
);
|
||||
|
||||
for ($i = 0; $i < count($sql); $i ++) {
|
||||
$connection->query($sql[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Separate each sql instruction in an array
|
||||
*
|
||||
* @param $sql
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareSql($sql)
|
||||
{
|
||||
$sql = str_replace(";',", "-CODE-", $sql);
|
||||
$query = array();
|
||||
|
||||
$tab = explode(";", $sql);
|
||||
|
||||
for($i=0; $i<count($tab); $i++){
|
||||
$queryTemp = str_replace("-CODE-", ";',", $tab[$i]);
|
||||
$queryTemp = str_replace("|", ";", $queryTemp);
|
||||
$query[] = $queryTemp;
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* create database if not exists
|
||||
*
|
||||
* @param \PDO $connection
|
||||
* @param $dbName
|
||||
*/
|
||||
protected function createDatabase(\PDO $connection, $dbName)
|
||||
{
|
||||
$connection->query(
|
||||
sprintf(
|
||||
"CREATE DATABASE IF NOT EXISTS %s CHARACTER SET utf8",
|
||||
$dbName
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* test database access
|
||||
*
|
||||
* @param $connectionInfo
|
||||
* @param OutputInterface $output
|
||||
* @return bool|\PDO
|
||||
*/
|
||||
protected function tryConnection($connectionInfo, OutputInterface $output)
|
||||
{
|
||||
|
||||
if (is_null($connectionInfo["dbName"])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$dsn = "mysql:host=%s";
|
||||
|
||||
try {
|
||||
$connection = new \PDO(
|
||||
sprintf($dsn, $connectionInfo["host"]),
|
||||
$connectionInfo["username"],
|
||||
$connectionInfo["password"]
|
||||
);
|
||||
} catch (\PDOException $e) {
|
||||
$output->writeln(array(
|
||||
"<error>Wrong connection information</error>"
|
||||
));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask to user all needed information
|
||||
*
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
* @return array
|
||||
*/
|
||||
protected function getConnectionInfo(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$dialog = $this->getHelperSet()->get('dialog');
|
||||
|
||||
$connectionInfo = array();
|
||||
|
||||
$connectionInfo["host"] = $dialog->askAndValidate(
|
||||
$output,
|
||||
$this->decorateInfo("Database host : "),
|
||||
function ($answer) {
|
||||
$answer = trim($answer);
|
||||
if (is_null($answer)) {
|
||||
throw new \RuntimeException("You must specify database host");
|
||||
}
|
||||
|
||||
return $answer;
|
||||
}
|
||||
);
|
||||
|
||||
$connectionInfo["dbName"] = $dialog->askAndValidate(
|
||||
$output,
|
||||
$this->decorateInfo("Database Name (if database does not exists, Thelia will try to create it) : "),
|
||||
function ($answer) {
|
||||
$answer = trim($answer);
|
||||
|
||||
if (is_null($answer)) {
|
||||
throw new \RuntimeException("You must specify database name");
|
||||
}
|
||||
|
||||
return $answer;
|
||||
}
|
||||
);
|
||||
|
||||
$connectionInfo["username"] = $dialog->askAndValidate(
|
||||
$output,
|
||||
$this->decorateInfo("Databse username : "),
|
||||
function ($answer) {
|
||||
$answer = trim($answer);
|
||||
|
||||
if (is_null($answer)) {
|
||||
throw new \RuntimeException("You must sprcify database username");
|
||||
}
|
||||
|
||||
return $answer;
|
||||
}
|
||||
);
|
||||
|
||||
$connectionInfo["password"] = $dialog->askHiddenResponse(
|
||||
$output,
|
||||
$this->decorateInfo("Database password : ")
|
||||
);
|
||||
|
||||
return $connectionInfo;
|
||||
}
|
||||
|
||||
protected function decorateInfo($text)
|
||||
{
|
||||
return sprintf("<info>%s</info>", $text);
|
||||
}
|
||||
|
||||
}
|
||||
104
documentation/api/files/Command/ModuleGenerateCommand.php.txt
Normal file
104
documentation/api/files/Command/ModuleGenerateCommand.php.txt
Normal file
@@ -0,0 +1,104 @@
|
||||
<?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 BaseModuleGenerate {
|
||||
|
||||
|
||||
|
||||
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();
|
||||
if(method_exists($this, "renderBlock")) {
|
||||
//impossible to change output class in CommandTester...
|
||||
$output->renderBlock(array(
|
||||
'',
|
||||
sprintf("module %s create with success", $this->module),
|
||||
"You can now configure your module and complete plugin.xml file",
|
||||
''
|
||||
), "bg=green;fg=black");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
$schemaContent = str_replace("%%NAMESPACE%%", $this->module, $schemaContent);
|
||||
|
||||
file_put_contents($this->moduleDirectory . DIRECTORY_SEPARATOR . "Config". DIRECTORY_SEPARATOR . "schema.xml", $schemaContent);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
<?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 Propel\Generator\Command\ModelBuildCommand;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
class ModuleGenerateModelCommand extends BaseModuleGenerate {
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName("module:generate:model")
|
||||
->setDescription("generate model for a specific module")
|
||||
->addArgument(
|
||||
"name",
|
||||
InputArgument::REQUIRED,
|
||||
"module name"
|
||||
)
|
||||
->addOption(
|
||||
"generate-sql",
|
||||
null,
|
||||
InputOption::VALUE_NONE,
|
||||
"with this option generate sql file at the same time"
|
||||
)
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->module = $this->formatModuleName($input->getArgument("name"));
|
||||
$this->moduleDirectory = THELIA_MODULE_DIR . DS . $this->module;
|
||||
|
||||
$fs = new Filesystem();
|
||||
|
||||
if ($fs->exists($this->moduleDirectory) === false) {
|
||||
throw new \RuntimeException(sprintf("%s module does not exists", $this->module));
|
||||
}
|
||||
|
||||
if ($fs->exists($this->moduleDirectory . DS . "Config" . DS . "schema.xml") === false) {
|
||||
throw new \RuntimeException("schema.xml not found in Config directory. Needed file for generating model");
|
||||
}
|
||||
|
||||
$this->generateModel($output);
|
||||
|
||||
$output->renderBlock(array(
|
||||
'',
|
||||
'Model generated successfuly',
|
||||
''
|
||||
), 'bg=green;fg=black');
|
||||
|
||||
if ($input->getOption("generate-sql")) {
|
||||
$output->writeln(' ');
|
||||
$this->generateSql($output);
|
||||
}
|
||||
}
|
||||
|
||||
protected function generateSql(OutputInterface $output)
|
||||
{
|
||||
|
||||
$command = $this->getApplication()->find("module:generate:sql");
|
||||
|
||||
$command->run(
|
||||
new ArrayInput(array(
|
||||
"command" => $command->getName(),
|
||||
"name" => $this->module
|
||||
)),
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
protected function generateModel(OutputInterface $output)
|
||||
{
|
||||
$fs = new Filesystem();
|
||||
$moduleBuildPropel = new ModelBuildCommand();
|
||||
$moduleBuildPropel->setApplication($this->getApplication());
|
||||
|
||||
$moduleBuildPropel->run(
|
||||
new ArrayInput(array(
|
||||
"command" => $moduleBuildPropel->getName(),
|
||||
"--output-dir" => THELIA_MODULE_DIR,
|
||||
"--input-dir" => $this->moduleDirectory . DS ."Config"
|
||||
)),
|
||||
$output
|
||||
);
|
||||
|
||||
$verifyDirectories = array(
|
||||
THELIA_MODULE_DIR . DS . "Thelia",
|
||||
$this->moduleDirectory . DS . "Model" . DS . "Thelia"
|
||||
);
|
||||
|
||||
foreach ($verifyDirectories as $directory) {
|
||||
if ($fs->exists($directory)) {
|
||||
$fs->remove($directory);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?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 Propel\Generator\Command\SqlBuildCommand;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Output\StreamOutput;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
class ModuleGenerateSqlCommand extends BaseModuleGenerate {
|
||||
|
||||
public function configure()
|
||||
{
|
||||
$this
|
||||
->setName("module:generate:sql")
|
||||
->setDescription("Generate the sql from schema.xml file")
|
||||
->addArgument(
|
||||
"name",
|
||||
InputArgument::REQUIRED,
|
||||
"Module name"
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->module = $this->formatModuleName($input->getArgument("name"));
|
||||
$this->moduleDirectory = THELIA_MODULE_DIR . DS . $this->module;
|
||||
|
||||
$fs = new Filesystem();
|
||||
|
||||
if ($fs->exists($this->moduleDirectory) === false) {
|
||||
throw new \RuntimeException(sprintf("%s module does not exists", $this->module));
|
||||
}
|
||||
|
||||
if ($fs->exists($this->moduleDirectory . DS . "Config" . DS . "schema.xml") === false) {
|
||||
throw new \RuntimeException("schema.xml not found in Config directory. Needed file for generating model");
|
||||
}
|
||||
|
||||
$sqlBuild = new SqlBuildCommand();
|
||||
$sqlBuild->setApplication($this->getApplication());
|
||||
|
||||
$sqlBuild->run(
|
||||
new ArrayInput(array(
|
||||
"command" => $sqlBuild->getName(),
|
||||
"--output-dir" => $this->moduleDirectory . DS ."Config",
|
||||
"--input-dir" => $this->moduleDirectory . DS ."Config"
|
||||
)),
|
||||
$output
|
||||
);
|
||||
|
||||
$output->renderBlock(array(
|
||||
'',
|
||||
'Sql generated successfuly',
|
||||
'File available in your module config directory',
|
||||
''
|
||||
), 'bg=green;fg=black');
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?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\Output;
|
||||
|
||||
|
||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
|
||||
class TheliaConsoleOutput extends ConsoleOutput{
|
||||
|
||||
public function renderBlock(array $messages, $style = "info")
|
||||
{
|
||||
$strlen = function ($string) {
|
||||
if (!function_exists('mb_strlen')) {
|
||||
return strlen($string);
|
||||
}
|
||||
|
||||
if (false === $encoding = mb_detect_encoding($string)) {
|
||||
return strlen($string);
|
||||
}
|
||||
|
||||
return mb_strlen($string, $encoding);
|
||||
};
|
||||
$length = 0;
|
||||
foreach ($messages as $message) {
|
||||
$length = ($strlen($message) > $length) ? $strlen($message) : $length;
|
||||
}
|
||||
$ouput = array();
|
||||
foreach ($messages as $message) {
|
||||
$output[] = "<" . $style . ">" . " " . $message . str_repeat(' ', $length - $strlen($message)) . " </" . $style . ">";
|
||||
}
|
||||
|
||||
$this->writeln($output);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user