diff --git a/core/lib/Thelia/Config/Resources/routing.xml b/core/lib/Thelia/Config/Resources/routing.xml index 9bb49451b..3c887ebe5 100755 --- a/core/lib/Thelia/Config/Resources/routing.xml +++ b/core/lib/Thelia/Config/Resources/routing.xml @@ -10,8 +10,14 @@ Symfony\Cmf\Component\Routing\DynamicRouter Symfony\Cmf\Component\Routing\ChainRouter Symfony\Component\Routing\Router + routing.xml + + + + + @@ -29,39 +35,30 @@ - %thelia.core_dir%/Config/Resources/routing + %kernel.cache_dir% - + - admin.xml + %router.xmlFileName% %kernel.cache_dir% %kernel.debug% - - - - - - front.xml - - %kernel.cache_dir% - %kernel.debug% - - - + + + diff --git a/core/lib/Thelia/Core/Bundle/TheliaBundle.php b/core/lib/Thelia/Core/Bundle/TheliaBundle.php index 9c8b8fedf..0aad541a5 100755 --- a/core/lib/Thelia/Core/Bundle/TheliaBundle.php +++ b/core/lib/Thelia/Core/Bundle/TheliaBundle.php @@ -59,7 +59,6 @@ class TheliaBundle extends Bundle $container ->addCompilerPass(new RegisterListenersPass()) ->addCompilerPass(new RegisterParserPluginPass()) - ->addCompilerPass(new RegisterRouterPass()) ; } diff --git a/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterRouterPass.php b/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterRouterPass.php deleted file mode 100644 index 2f7624de5..000000000 --- a/core/lib/Thelia/Core/DependencyInjection/Compiler/RegisterRouterPass.php +++ /dev/null @@ -1,54 +0,0 @@ -. */ -/* */ -/*************************************************************************************/ - -namespace Thelia\Core\DependencyInjection\Compiler; - - -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Reference; - -class RegisterRouterPass implements CompilerPassInterface -{ - - /** - * You can modify the container here before it is dumped to PHP code. - * - * @param ContainerBuilder $container - * - * @api - */ - public function process(ContainerBuilder $container) - { - if (!$container->hasDefinition("router.chainRequest")) { - return ; - } - - $chainRouter = $container->getDefinition("router.chainRequest"); - - foreach ($container->findTaggedServiceIds("router.register") as $id => $router) { - $priority = isset($router[0]['priority']) ? $router[0]['priority'] : 0; - $chainRouter->addMethodCall("add", array(new Reference($id), $priority)); - } - } -} \ No newline at end of file diff --git a/core/lib/Thelia/Core/DependencyInjection/ContainerAwareAdmin.php b/core/lib/Thelia/Core/DependencyInjection/Loader/CollectionXmlFileLoader.php similarity index 62% rename from core/lib/Thelia/Core/DependencyInjection/ContainerAwareAdmin.php rename to core/lib/Thelia/Core/DependencyInjection/Loader/CollectionXmlFileLoader.php index 3792c22cc..4ae318e9b 100644 --- a/core/lib/Thelia/Core/DependencyInjection/ContainerAwareAdmin.php +++ b/core/lib/Thelia/Core/DependencyInjection/Loader/CollectionXmlFileLoader.php @@ -20,34 +20,49 @@ /* along with this program. If not, see . */ /* */ /*************************************************************************************/ +namespace Thelia\Core\DependencyInjection\Loader; -namespace Thelia\Core\DependencyInjection; +class CollectionXmlFileLoader { + protected $files = array(); + protected $cacheDir; + protected $outputName; -use Symfony\Component\DependencyInjection\ContainerAwareInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; -use Thelia\Core\Context; - -class ContainerAwareAdmin implements ContainerAwareInterface { - - /** - * @var ContainerInterface - * - * @api - */ - protected $container; - - /** - * Sets the Container. - * - * @param ContainerInterface|null $container A ContainerInterface instance or null - * - * @api - */ - public function setContainer(ContainerInterface $container = null) + public function __construct($cacheDir, $outputName, array $files = array()) { - $container->get('thelia.envContext')->setContext(Context::CONTEXT_BACK_OFFICE); - $this->container = $container; + $this->cacheDir = $cacheDir; + $this->outputName = $outputName; + $this->files = $files; } + + public function addFile($file) + { + $this->files[] = $file; + } + + public function process() + { + $pattern = ''; + + $outputPattern = << + + + %s + +EOF; + $imports = array(); + foreach ($this->files as $file) { + $imports[] = sprintf($pattern, $file); + } + + + $output = sprintf($outputPattern, implode($imports)); + file_put_contents($this->cacheDir .'/'. $this->outputName, $output); + + } + } \ No newline at end of file diff --git a/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php b/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php index a95e7d668..c76362b80 100755 --- a/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php +++ b/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php @@ -65,6 +65,8 @@ class XmlFileLoader extends FileLoader $this->parseForms($xml); + $this->parseRouting($xml); + $this->parseDefinitions($xml, $path); } @@ -166,6 +168,30 @@ class XmlFileLoader extends FileLoader $this->container->setParameter("Thelia.parser.filters", $filterConfig); } + /** + * parse routing properties + * + * @param SimpleXMLElement $xml + */ + protected function parseRouting(SimpleXMLElement $xml) + { + if (false === $routing = $xml->xpath("//config:routing/config:file")) { + return; + } + + try { + $routingConfig = $this->container->getParameter("thelia.routing.files"); + } catch (ParameterNotFoundException $e) { + $routingConfig = array(); + } + + foreach ($routing as $file) { + $routingConfig[] = $file->getAttributeAsPhp("path"); + } + + $this->container->setParameter("thelia.routing.files", $routingConfig); + } + /** * parse BaseParams property * 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 ef33d400a..43c0eff65 100755 --- 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 @@ -16,6 +16,7 @@ + @@ -54,6 +55,16 @@ + + + + + + + + + + diff --git a/core/lib/Thelia/Core/Thelia.php b/core/lib/Thelia/Core/Thelia.php index 526024707..1832bdfe1 100755 --- a/core/lib/Thelia/Core/Thelia.php +++ b/core/lib/Thelia/Core/Thelia.php @@ -39,6 +39,7 @@ use Symfony\Component\Yaml\Yaml; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Thelia\Core\Bundle; +use Thelia\Core\DependencyInjection\Loader\CollectionXmlFileLoader; use Thelia\Log\Tlog; use Thelia\Config\DatabaseConfiguration; use Thelia\Config\DefinePropel; @@ -149,6 +150,14 @@ class Thelia extends Kernel $this->loadConfiguration($container); $container->customCompile(); + $collectionFileLoader = new CollectionXmlFileLoader( + $container->getParameter("kernel.cache_dir"), + $container->getParameter("router.xmlFileName"), + $container->getParameter("thelia.routing.files") + ); + + $collectionFileLoader->process(); + return $container; } @@ -196,6 +205,7 @@ class Thelia extends Kernel $parameters["thelia.root_dir"] = THELIA_ROOT; $parameters["thelia.core_dir"] = THELIA_ROOT . "core/lib/Thelia"; + $parameters["thelia.module_dir"] = THELIA_MODULE_DIR; return $parameters; }