add Thelia conf into Kernel process
This commit is contained in:
77
core/lib/Thelia/Config/Dumper/TpexConfigDumper.php
Normal file
77
core/lib/Thelia/Config/Dumper/TpexConfigDumper.php
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
<?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\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 = <<<EOF
|
||||||
|
<?php
|
||||||
|
/* File generated by \Thelia\Config\Dumper\TpexConfigDumper */
|
||||||
|
class TpexConfig
|
||||||
|
{
|
||||||
|
|
||||||
|
public function getLoopConfig()
|
||||||
|
{
|
||||||
|
return {$this->loops};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFilterConfig()
|
||||||
|
{
|
||||||
|
return {$this->filters};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBaseParamConfig()
|
||||||
|
{
|
||||||
|
return {$this->baseParams};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLoopTestConfig()
|
||||||
|
{
|
||||||
|
return {$this->loopTests};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOF;
|
||||||
|
|
||||||
|
return $code;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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->init($this->container->get("request"), $this->container->get("dispatcher"), $content, THELIA_TEMPLATE_DIR . rtrim($this->template, "/") . "/");
|
||||||
$tpex->configure(
|
$tpex->configure(
|
||||||
$this->container->get("loop"),
|
$this->container->getParameter("Tpex.loop"),
|
||||||
$this->container->get("filter"),
|
$this->container->getParameter("Tpex.filter"),
|
||||||
$this->container->get("baseParam"),
|
$this->container->getParameter("Tpex.baseParam"),
|
||||||
$this->container->get("testLoop")
|
$this->container->getParameter("Tpex.testLoop")
|
||||||
);
|
);
|
||||||
$this->setContent($tpex->execute());
|
$this->setContent($tpex->execute());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ namespace Thelia\Core;
|
|||||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\HttpKernel\Kernel;
|
use Symfony\Component\HttpKernel\Kernel;
|
||||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||||
use Symfony\Component\Config\Definition\Processor;
|
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\Resource\FileResource;
|
||||||
use Symfony\Component\Config\Util\XmlUtils;
|
use Symfony\Component\Config\Util\XmlUtils;
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||||
|
|
||||||
|
|
||||||
use Thelia\Core\Bundle;
|
use Thelia\Core\Bundle;
|
||||||
@@ -46,6 +48,7 @@ use Thelia\Log\Tlog;
|
|||||||
use Thelia\Config\DatabaseConfiguration;
|
use Thelia\Config\DatabaseConfiguration;
|
||||||
use Thelia\Config\DefinePropel;
|
use Thelia\Config\DefinePropel;
|
||||||
use Thelia\Config\Dumper\TpexConfigDumper;
|
use Thelia\Config\Dumper\TpexConfigDumper;
|
||||||
|
use Thelia\Core\TheliaContainerBuilder;
|
||||||
|
|
||||||
use Propel;
|
use Propel;
|
||||||
use PropelConfiguration;
|
use PropelConfiguration;
|
||||||
@@ -98,14 +101,14 @@ class Thelia extends Kernel
|
|||||||
* Initialize all plugins
|
* Initialize all plugins
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function loadConfiguration()
|
public function loadConfiguration(ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* TODO :
|
* TODO :
|
||||||
* - Retrieve all actives plugins
|
* - Retrieve all actives plugins
|
||||||
* - load config (create a cache and use this cache
|
* - load config (create a cache and use this cache
|
||||||
*/
|
*/
|
||||||
$container = $this->getContainer();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set all listener here.
|
* Set all listener here.
|
||||||
@@ -119,29 +122,15 @@ class Thelia extends Kernel
|
|||||||
/**
|
/**
|
||||||
* manage Tpex configuration here
|
* 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;
|
return $container;
|
||||||
|
|
||||||
$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());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function generateTpexConfigCache(ConfigCache $cache)
|
protected function generateTpexConfig(ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$loopConfig = array();
|
$loopConfig = array();
|
||||||
$filterConfig = array();
|
$filterConfig = array();
|
||||||
@@ -154,7 +143,7 @@ class Thelia extends Kernel
|
|||||||
$masterConfigFile = THELIA_ROOT . "/core/lib/Thelia/config.xml";
|
$masterConfigFile = THELIA_ROOT . "/core/lib/Thelia/config.xml";
|
||||||
|
|
||||||
if (file_exists($masterConfigFile)) {
|
if (file_exists($masterConfigFile)) {
|
||||||
$resources[] = new FileResource($masterConfigFile);
|
$container->addResource(new FileResource($masterConfigFile));
|
||||||
|
|
||||||
$dom = XmlUtils::loadFile($masterConfigFile);
|
$dom = XmlUtils::loadFile($masterConfigFile);
|
||||||
|
|
||||||
@@ -173,7 +162,7 @@ class Thelia extends Kernel
|
|||||||
foreach ($modules as $module) {
|
foreach ($modules as $module) {
|
||||||
$configFile = THELIA_PLUGIN_DIR . "/" . ucfirst($module->getCode()) . "/Config/config.xml";
|
$configFile = THELIA_PLUGIN_DIR . "/" . ucfirst($module->getCode()) . "/Config/config.xml";
|
||||||
if (file_exists($configFile)) {
|
if (file_exists($configFile)) {
|
||||||
$resources[] = new FileResource($configFile);
|
$container->addResource(new FileResource($configFile));
|
||||||
$dom = XmlUtils::loadFile($configFile);
|
$dom = XmlUtils::loadFile($configFile);
|
||||||
|
|
||||||
$loopConfig = array_merge($loopConfig, $this->processConfig($dom->getElementsByTagName("loop")));
|
$loopConfig = array_merge($loopConfig, $this->processConfig($dom->getElementsByTagName("loop")));
|
||||||
@@ -193,14 +182,15 @@ class Thelia extends Kernel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$tpexConfig = new TpexConfigDumper(
|
$container->setParameter("Tpex.loop", $loopConfig);
|
||||||
$loopConfig,
|
|
||||||
$filterConfig,
|
|
||||||
$baseParamConfig,
|
|
||||||
$loopTestConfig
|
|
||||||
);
|
|
||||||
|
|
||||||
$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)
|
protected function processConfig(\DOMNodeList $elements)
|
||||||
@@ -222,17 +212,32 @@ class Thelia extends Kernel
|
|||||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a new ContainerBuilder instance used to build the service container.
|
||||||
|
*
|
||||||
|
* @return ContainerBuilder
|
||||||
|
*/
|
||||||
|
protected function getContainerBuilder()
|
||||||
|
{
|
||||||
|
return new TheliaContainerBuilder(new ParameterBag($this->getKernelParameters()));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Builds the service container.
|
||||||
*
|
*
|
||||||
* boot parent kernel and after current kernel
|
* @return ContainerBuilder The compiled service container
|
||||||
*
|
*
|
||||||
|
* @throws \RuntimeException
|
||||||
*/
|
*/
|
||||||
public function boot()
|
protected function buildContainer()
|
||||||
{
|
{
|
||||||
parent::boot();
|
$container = parent::buildContainer();
|
||||||
|
|
||||||
$this->loadConfiguration();
|
$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
|
* return available bundle
|
||||||
*
|
*
|
||||||
|
|||||||
38
core/lib/Thelia/Core/TheliaContainerBuilder.php
Normal file
38
core/lib/Thelia/Core/TheliaContainerBuilder.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?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\DependencyInjection\ContainerBuilder;
|
||||||
|
|
||||||
|
class TheliaContainerBuilder extends ContainerBuilder
|
||||||
|
{
|
||||||
|
|
||||||
|
public function compile(){}
|
||||||
|
|
||||||
|
public function customCompile()
|
||||||
|
{
|
||||||
|
parent::compile();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
46
core/lib/Thelia/Tests/Config/Dumper/TpexConfigDumperTest.php
Normal file
46
core/lib/Thelia/Tests/Config/Dumper/TpexConfigDumperTest.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?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\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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
25
core/lib/Thelia/Tests/Fixtures/Dumper/Config/Empty.php
Normal file
25
core/lib/Thelia/Tests/Fixtures/Dumper/Config/Empty.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
/* File generated by \Thelia\Config\Dumper\TpexConfigDumper */
|
||||||
|
class TpexConfig
|
||||||
|
{
|
||||||
|
|
||||||
|
public function getLoopConfig()
|
||||||
|
{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFilterConfig()
|
||||||
|
{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBaseParamConfig()
|
||||||
|
{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLoopTestConfig()
|
||||||
|
{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
8
core/lib/Thelia/config.xml
Normal file
8
core/lib/Thelia/config.xml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<root>
|
||||||
|
<testLoops>
|
||||||
|
<testLoop name="equal" class="Test\TestLoop\Equal"/>
|
||||||
|
</testLoops>
|
||||||
|
<loops>
|
||||||
|
<loop name="foo" class="Foo\Bar"/>
|
||||||
|
</loops>
|
||||||
|
</root>
|
||||||
6
local/plugins/Test/Config/config.xml
Normal file
6
local/plugins/Test/Config/config.xml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<plugin>
|
||||||
|
<loops>
|
||||||
|
<loop name="foo" class="Test\Loop\Foo"/>
|
||||||
|
<loop name="doobitch" class="Test\Loop\Doobitch"/>
|
||||||
|
</loops>
|
||||||
|
</plugin>
|
||||||
@@ -24,3 +24,5 @@ $thelia = new Thelia("dev", true);
|
|||||||
$response = $thelia->handle($request)->prepare($request)->send();
|
$response = $thelia->handle($request)->prepare($request)->send();
|
||||||
|
|
||||||
$thelia->terminate($request, $response);
|
$thelia->terminate($request, $response);
|
||||||
|
|
||||||
|
echo "page parsed in : " . (microtime(true) - $thelia->getStartTime());
|
||||||
Reference in New Issue
Block a user