diff --git a/core/lib/Thelia/Config/Dumper/TpexConfigDumper.php b/core/lib/Thelia/Config/Dumper/TpexConfigDumper.php new file mode 100644 index 000000000..7c532bdde --- /dev/null +++ b/core/lib/Thelia/Config/Dumper/TpexConfigDumper.php @@ -0,0 +1,77 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Config\Dumper; + + +class TpexConfigDumper { + + protected $loops; + protected $filters; + protected $baseParams; + protected $loopTests; + + public function __construct(array $loops, array $filters, array $baseParams, array $loopTests) + { + $this->loops = var_export($loops, true); + $this->filters = var_export($filters, true); + $this->baseParams = var_export($baseParams, true); + $this->loopTests = var_export($loopTests, true); + } + + public function dump() + { + + $code = <<loops}; + } + + public function getFilterConfig() + { + return {$this->filters}; + } + + public function getBaseParamConfig() + { + return {$this->baseParams}; + } + + public function getLoopTestConfig() + { + return {$this->loopTests}; + } +} +EOF; + + return $code; + } + + +} \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Parser.php b/core/lib/Thelia/Core/Template/Parser.php index 947e3d85a..346ab2bfc 100644 --- a/core/lib/Thelia/Core/Template/Parser.php +++ b/core/lib/Thelia/Core/Template/Parser.php @@ -152,10 +152,10 @@ class Parser implements ParserInterface $tpex->init($this->container->get("request"), $this->container->get("dispatcher"), $content, THELIA_TEMPLATE_DIR . rtrim($this->template, "/") . "/"); $tpex->configure( - $this->container->get("loop"), - $this->container->get("filter"), - $this->container->get("baseParam"), - $this->container->get("testLoop") + $this->container->getParameter("Tpex.loop"), + $this->container->getParameter("Tpex.filter"), + $this->container->getParameter("Tpex.baseParam"), + $this->container->getParameter("Tpex.testLoop") ); $this->setContent($tpex->execute()); } diff --git a/core/lib/Thelia/Core/Thelia.php b/core/lib/Thelia/Core/Thelia.php index f0512ad11..08980f01d 100644 --- a/core/lib/Thelia/Core/Thelia.php +++ b/core/lib/Thelia/Core/Thelia.php @@ -32,6 +32,7 @@ namespace Thelia\Core; * @author Manuel Raynaud */ +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\Config\Definition\Processor; @@ -39,6 +40,7 @@ use Symfony\Component\Config\ConfigCache; use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\Config\Util\XmlUtils; use Symfony\Component\Yaml\Yaml; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Thelia\Core\Bundle; @@ -46,6 +48,7 @@ use Thelia\Log\Tlog; use Thelia\Config\DatabaseConfiguration; use Thelia\Config\DefinePropel; use Thelia\Config\Dumper\TpexConfigDumper; +use Thelia\Core\TheliaContainerBuilder; use Propel; use PropelConfiguration; @@ -98,14 +101,14 @@ class Thelia extends Kernel * Initialize all plugins * */ - public function loadConfiguration() + public function loadConfiguration(ContainerBuilder $container) { /** * TODO : * - Retrieve all actives plugins * - load config (create a cache and use this cache */ - $container = $this->getContainer(); + /** * Set all listener here. @@ -119,29 +122,15 @@ class Thelia extends Kernel /** * manage Tpex configuration here */ + $container = $this->generateTpexConfig($container); - $file = $this->getCacheDir() . "/TpexConfig.php"; - $configCache = new ConfigCache($file, $this->debug); - if (!$configCache->isFresh()) { - $this->generateTpexConfigCache($configCache); - } - require_once $configCache; - - $this->tpexConfig = new \TpexConfig(); - - $container->set("loop", $this->tpexConfig->getLoopConfig()); - - $container->set("filter", $this->tpexConfig->getFilterConfig()); - - $container->set("baseParam", $this->tpexConfig->getBaseParamConfig()); - - $container->set("testLoop", $this->tpexConfig->getLoopTestConfig()); + return $container; } - protected function generateTpexConfigCache(ConfigCache $cache) + protected function generateTpexConfig(ContainerBuilder $container) { $loopConfig = array(); $filterConfig = array(); @@ -154,7 +143,7 @@ class Thelia extends Kernel $masterConfigFile = THELIA_ROOT . "/core/lib/Thelia/config.xml"; if (file_exists($masterConfigFile)) { - $resources[] = new FileResource($masterConfigFile); + $container->addResource(new FileResource($masterConfigFile)); $dom = XmlUtils::loadFile($masterConfigFile); @@ -173,7 +162,7 @@ class Thelia extends Kernel foreach ($modules as $module) { $configFile = THELIA_PLUGIN_DIR . "/" . ucfirst($module->getCode()) . "/Config/config.xml"; if (file_exists($configFile)) { - $resources[] = new FileResource($configFile); + $container->addResource(new FileResource($configFile)); $dom = XmlUtils::loadFile($configFile); $loopConfig = array_merge($loopConfig, $this->processConfig($dom->getElementsByTagName("loop"))); @@ -193,14 +182,15 @@ class Thelia extends Kernel } } - $tpexConfig = new TpexConfigDumper( - $loopConfig, - $filterConfig, - $baseParamConfig, - $loopTestConfig - ); + $container->setParameter("Tpex.loop", $loopConfig); - $cache->write($tpexConfig->dump(), $resources); + $container->setParameter("Tpex.filter", $filterConfig); + + $container->setParameter("Tpex.baseParam", $baseParamConfig); + + $container->setParameter("Tpex.testLoop", $loopTestConfig); + + return $container; } protected function processConfig(\DOMNodeList $elements) @@ -221,18 +211,33 @@ class Thelia extends Kernel * * @param \Symfony\Component\HttpFoundation\Request $request */ - /** - * - * boot parent kernel and after current kernel - * + * Gets a new ContainerBuilder instance used to build the service container. + * + * @return ContainerBuilder */ - public function boot() + protected function getContainerBuilder() { - parent::boot(); - - $this->loadConfiguration(); + return new TheliaContainerBuilder(new ParameterBag($this->getKernelParameters())); + } + + /** + * Builds the service container. + * + * @return ContainerBuilder The compiled service container + * + * @throws \RuntimeException + */ + protected function buildContainer() + { + $container = parent::buildContainer(); + + $container = $this->loadConfiguration($container); + + $container->customCompile(); + + return $container; } /** @@ -268,23 +273,6 @@ class Thelia extends Kernel } } - /** - * Builds the service container. - * - * @return ContainerBuilder The compiled service container - */ -// protected function buildContainer() -// { -// $container = $this->getContainerBuilder(); -// $container->set('kernel', $this); -// -// foreach ($this->bundles as $bundle) { -// $bundle->build($container); -// } -// -// return $container; -// } - /** * return available bundle * diff --git a/core/lib/Thelia/Core/TheliaContainerBuilder.php b/core/lib/Thelia/Core/TheliaContainerBuilder.php new file mode 100644 index 000000000..997f29a40 --- /dev/null +++ b/core/lib/Thelia/Core/TheliaContainerBuilder.php @@ -0,0 +1,38 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core; + +use Symfony\Component\DependencyInjection\ContainerBuilder; + +class TheliaContainerBuilder extends ContainerBuilder +{ + + public function compile(){} + + public function customCompile() + { + parent::compile(); + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Tests/Config/Dumper/TpexConfigDumperTest.php b/core/lib/Thelia/Tests/Config/Dumper/TpexConfigDumperTest.php new file mode 100644 index 000000000..47cd7d982 --- /dev/null +++ b/core/lib/Thelia/Tests/Config/Dumper/TpexConfigDumperTest.php @@ -0,0 +1,46 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Tests\Config\Dumper; + +use Thelia\Config\Dumper\TpexConfigDumper; + + +class TpexConfigDumperTest extends \PHPUnit_Framework_TestCase +{ + + static protected $fixturePath; + + public static function setUpBeforeClass() + { + self::$fixturePath = realpath(__DIR__ . "/../Fixtures/Dumper/Config"); + } + + public function testDumpWithEmptyConfig() + { + $tpexDumper = new TpexConfigDumper(array(), array(), array(), array()); + + $this->assertStringEqualsFile(self::$fixturePath . "/Empty.php", $tpexDumper->dump()); + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Tests/Fixtures/Dumper/Config/Empty.php b/core/lib/Thelia/Tests/Fixtures/Dumper/Config/Empty.php new file mode 100644 index 000000000..749fc1896 --- /dev/null +++ b/core/lib/Thelia/Tests/Fixtures/Dumper/Config/Empty.php @@ -0,0 +1,25 @@ + + + + + + + + \ No newline at end of file diff --git a/local/plugins/Test/Config/config.xml b/local/plugins/Test/Config/config.xml new file mode 100644 index 000000000..f9c2aeb0c --- /dev/null +++ b/local/plugins/Test/Config/config.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/web/index_dev.php b/web/index_dev.php index f5898f61a..058c6f36a 100644 --- a/web/index_dev.php +++ b/web/index_dev.php @@ -24,3 +24,5 @@ $thelia = new Thelia("dev", true); $response = $thelia->handle($request)->prepare($request)->send(); $thelia->terminate($request, $response); + +echo "page parsed in : " . (microtime(true) - $thelia->getStartTime()); \ No newline at end of file