From af086a55dada839e3329795a5080f563e70bd991 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 3 Jun 2013 13:12:34 +0200 Subject: [PATCH] implement command process --- Thelia | 18 +++++ core/lib/Thelia/Command/ClearCacheCommand.php | 55 +++++++++++++ core/lib/Thelia/Config/Resources/config.xml | 4 + core/lib/Thelia/Core/Application.php | 79 +++++++++++++++++++ .../Loader/schema/dic/config/thelia-1.0.xsd | 3 +- core/lib/Thelia/Core/Thelia.php | 2 + 6 files changed, 160 insertions(+), 1 deletion(-) create mode 100755 Thelia create mode 100644 core/lib/Thelia/Command/ClearCacheCommand.php create mode 100644 core/lib/Thelia/Core/Application.php diff --git a/Thelia b/Thelia new file mode 100755 index 000000000..31eed0c01 --- /dev/null +++ b/Thelia @@ -0,0 +1,18 @@ +#!/usr/bin/env php +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); \ No newline at end of file diff --git a/core/lib/Thelia/Command/ClearCacheCommand.php b/core/lib/Thelia/Command/ClearCacheCommand.php new file mode 100644 index 000000000..d6d058519 --- /dev/null +++ b/core/lib/Thelia/Command/ClearCacheCommand.php @@ -0,0 +1,55 @@ +. */ +/* */ +/*************************************************************************************/ + +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")); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index b076a1d59..ceb75b68f 100644 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -12,6 +12,10 @@ + + + + diff --git a/core/lib/Thelia/Core/Application.php b/core/lib/Thelia/Core/Application.php new file mode 100644 index 000000000..be2cdb46a --- /dev/null +++ b/core/lib/Thelia/Core/Application.php @@ -0,0 +1,79 @@ +. */ +/* */ +/*************************************************************************************/ + +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()); + } + } + + + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/DependencyInjection/Loader/schema/dic/config/thelia-1.0.xsd b/core/lib/Thelia/Core/DependencyInjection/Loader/schema/dic/config/thelia-1.0.xsd index a3b4bd83f..2c700a34e 100644 --- a/core/lib/Thelia/Core/DependencyInjection/Loader/schema/dic/config/thelia-1.0.xsd +++ b/core/lib/Thelia/Core/DependencyInjection/Loader/schema/dic/config/thelia-1.0.xsd @@ -15,6 +15,7 @@ + @@ -66,7 +67,7 @@ - + diff --git a/core/lib/Thelia/Core/Thelia.php b/core/lib/Thelia/Core/Thelia.php index a5a24532a..600779ad1 100644 --- a/core/lib/Thelia/Core/Thelia.php +++ b/core/lib/Thelia/Core/Thelia.php @@ -57,6 +57,8 @@ use PropelConfiguration; class Thelia extends Kernel { + const THELIA_VERSION = 0.1; + protected $tpexConfig; public function init()