implement command process
This commit is contained in:
18
Thelia
Executable file
18
Thelia
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
#!/usr/bin/env php
|
||||||
|
<?php
|
||||||
|
|
||||||
|
set_time_limit(0);
|
||||||
|
|
||||||
|
require __DIR__ . '/core/bootstrap.php';
|
||||||
|
|
||||||
|
use Thelia\Core\Thelia;
|
||||||
|
use Thelia\Core\Application;
|
||||||
|
use Symfony\Component\Console\Input\ArgvInput;
|
||||||
|
|
||||||
|
$input = new ArgvInput();
|
||||||
|
$env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'dev');
|
||||||
|
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod';
|
||||||
|
|
||||||
|
$thelia = new Thelia($env, $debug);
|
||||||
|
$application = new Application($thelia);
|
||||||
|
$application->run($input);
|
||||||
55
core/lib/Thelia/Command/ClearCacheCommand.php
Normal file
55
core/lib/Thelia/Command/ClearCacheCommand.php
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?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\Console\Input\InputArgument;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
|
use Symfony\Component\Filesystem\Exception\IOException;
|
||||||
|
|
||||||
|
class ClearCacheCommand extends Command
|
||||||
|
{
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
$this
|
||||||
|
->setName("clear:cache")
|
||||||
|
->setDescription("Invalidate all caches");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
|
||||||
|
$cacheDir = $this->getApplication()->getContainer()->getParameter("kernel.cache_dir");
|
||||||
|
|
||||||
|
if (!is_writable($cacheDir)) {
|
||||||
|
throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $cacheDir));
|
||||||
|
}
|
||||||
|
|
||||||
|
$fs = new Filesystem();
|
||||||
|
$fs->remove($this->getApplication()->getKernel()->getContainer()->getParameter("kernel.cache_dir"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,10 @@
|
|||||||
<loop class="Thelia\Core\Template\Loop\Category" name="category"/>
|
<loop class="Thelia\Core\Template\Loop\Category" name="category"/>
|
||||||
</loops>
|
</loops>
|
||||||
|
|
||||||
|
<commands>
|
||||||
|
<command class="Thelia\Command\ClearCacheCommand"/>
|
||||||
|
</commands>
|
||||||
|
|
||||||
<services>
|
<services>
|
||||||
<service id="event_dispatcher" class="Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher">
|
<service id="event_dispatcher" class="Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher">
|
||||||
<argument type="service" id="service_container" />
|
<argument type="service" id="service_container" />
|
||||||
|
|||||||
79
core/lib/Thelia/Core/Application.php
Normal file
79
core/lib/Thelia/Core/Application.php
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
<?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\Core;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Application as BaseApplication;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\HttpKernel\KernelInterface;
|
||||||
|
|
||||||
|
|
||||||
|
class Application extends BaseApplication
|
||||||
|
{
|
||||||
|
|
||||||
|
public $kernel;
|
||||||
|
|
||||||
|
public function __construct(KernelInterface $kernel)
|
||||||
|
{
|
||||||
|
$this->kernel = $kernel;
|
||||||
|
|
||||||
|
parent::__construct("Thelia", Thelia::THELIA_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getKernel()
|
||||||
|
{
|
||||||
|
return $this->kernel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getContainer()
|
||||||
|
{
|
||||||
|
return $this->kernel->getContainer();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function doRun(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
$this->registerCommands();
|
||||||
|
|
||||||
|
return parent::doRun($input, $output);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function registerCommands()
|
||||||
|
{
|
||||||
|
$this->kernel->boot();
|
||||||
|
|
||||||
|
$container = $this->kernel->getContainer();
|
||||||
|
|
||||||
|
foreach($container->getParameter("command.definition") as $command)
|
||||||
|
{
|
||||||
|
$r = new \ReflectionClass($command);
|
||||||
|
|
||||||
|
if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) {
|
||||||
|
$this->add($r->newInstance());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
<xsd:element name="testLoops" type="testLoops" />
|
<xsd:element name="testLoops" type="testLoops" />
|
||||||
<xsd:element name="services" type="services" />
|
<xsd:element name="services" type="services" />
|
||||||
<xsd:element name="parameters" type="parameters"/>
|
<xsd:element name="parameters" type="parameters"/>
|
||||||
|
<xsd:element name="commands" type="commands"/>
|
||||||
</xsd:choice>
|
</xsd:choice>
|
||||||
</xsd:complexType>
|
</xsd:complexType>
|
||||||
|
|
||||||
@@ -66,7 +67,7 @@
|
|||||||
|
|
||||||
<xsd:complexType name="commands">
|
<xsd:complexType name="commands">
|
||||||
<xsd:choice minOccurs="1" maxOccurs="unbounded" >
|
<xsd:choice minOccurs="1" maxOccurs="unbounded" >
|
||||||
<xsd:element name="loop" type="command"/>
|
<xsd:element name="command" type="command"/>
|
||||||
</xsd:choice>
|
</xsd:choice>
|
||||||
</xsd:complexType>
|
</xsd:complexType>
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ use PropelConfiguration;
|
|||||||
class Thelia extends Kernel
|
class Thelia extends Kernel
|
||||||
{
|
{
|
||||||
|
|
||||||
|
const THELIA_VERSION = 0.1;
|
||||||
|
|
||||||
protected $tpexConfig;
|
protected $tpexConfig;
|
||||||
|
|
||||||
public function init()
|
public function init()
|
||||||
|
|||||||
Reference in New Issue
Block a user