From 391296d2913a2df6b573146fb5e7469905b6e0be Mon Sep 17 00:00:00 2001 From: franck Date: Wed, 19 Jun 2013 17:12:32 +0200 Subject: [PATCH] Beginning integration of template directives. Config xsd changed. --- core/lib/Thelia/Config/Resources/config.xml | 45 ++++++++++--------- .../Loader/XmlFileLoader.php | 43 ++++-------------- .../Loader/schema/dic/config/thelia-1.0.xsd | 32 +++++-------- .../Core/Template/Smarty/SmartyParser.php | 41 ----------------- 4 files changed, 42 insertions(+), 119 deletions(-) diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 4199ce349..d5320fca2 100644 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -4,14 +4,24 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd"> - - - - + + + + + + + + + + @@ -55,10 +65,18 @@ - %tpex.loop% + %thelia.parser.loops% + + + + + + + + @@ -66,23 +84,6 @@ - - - - - %tpex.loop% - - - %tpex.filter% - - - %tpex.baseParam% - - - %tpex.testLoop% - - - diff --git a/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php b/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php index e4ba1501d..58c81a64a 100644 --- a/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php +++ b/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php @@ -57,9 +57,7 @@ class XmlFileLoader extends FileLoader $this->parseFilters($xml); - $this->parseBaseParams($xml); - - $this->parseTestLoops($xml); + $this->parseTemplateDirectives($xml); $this->parseParameters($xml); @@ -112,7 +110,7 @@ class XmlFileLoader extends FileLoader return; } try { - $loopConfig = $this->container->getParameter("Tpex.loop"); + $loopConfig = $this->container->getParameter("Thelia.parser.loops"); } catch (\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException $e) { $loopConfig = array(); } @@ -121,7 +119,7 @@ class XmlFileLoader extends FileLoader $loopConfig[$loop->getAttributeAsPhp("name")] = $loop->getAttributeAsPhp("class"); } - $this->container->setParameter("Tpex.loop", $loopConfig); + $this->container->setParameter("Thelia.parser.loops", $loopConfig); } /** @@ -135,7 +133,7 @@ class XmlFileLoader extends FileLoader return; } try { - $filterConfig = $this->container->getParameter("Tpex.filter"); + $filterConfig = $this->container->getParameter("Thelia.parser.filters"); } catch (\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException $e) { $filterConfig = array(); } @@ -144,7 +142,7 @@ class XmlFileLoader extends FileLoader $filterConfig[$filter->getAttributeAsPhp("name")] = $filter->getAttributeAsPhp("class"); } - $this->container->setParameter("Tpex.filter", $filterConfig); + $this->container->setParameter("Thelia.parser.filters", $filterConfig); } /** @@ -152,13 +150,13 @@ class XmlFileLoader extends FileLoader * * @param SimpleXMLElement $xml */ - protected function parseBaseParams(SimpleXMLElement $xml) + protected function parseTemplateDirectives(SimpleXMLElement $xml) { - if (false === $baseParams = $xml->xpath('//config:baseParams/config:baseParam')) { + if (false === $baseParams = $xml->xpath('//config:templateDirectives/config:templateDirective')) { return; } try { - $baseParamConfig = $this->container->getParameter("Tpex.baseParam"); + $baseParamConfig = $this->container->getParameter("Thelia.parser.templateDirectives"); } catch (\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException $e) { $baseParamConfig = array(); } @@ -167,30 +165,7 @@ class XmlFileLoader extends FileLoader $baseParamConfig[$baseParam->getAttributeAsPhp("name")] = $baseParam->getAttributeAsPhp("class"); } - $this->container->setParameter("Tpex.baseParam", $baseParamConfig); - } - - /** - * parse testLoops property - * - * @param SimpleXMLElement $xml - */ - protected function parseTestLoops(SimpleXMLElement $xml) - { - if (false === $testLoops = $xml->xpath('//config:testLoops/config:testLoop')) { - return; - } - try { - $baseParamConfig = $this->container->getParameter("Tpex.baseParam"); - } catch (\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException $e) { - $baseParamConfig = array(); - } - - foreach ($testLoops as $testLoop) { - $baseParamConfig[$testLoop->getAttributeAsPhp("name")] = $testLoop->getAttributeAsPhp("class"); - } - - $this->container->setParameter("Tpex.testLoop", $baseParamConfig); + $this->container->setParameter("Thelia.parser.templateDirectives", $baseParamConfig); } /** 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 2c700a34e..33f563040 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 @@ -10,9 +10,8 @@ - - - + + @@ -55,7 +54,7 @@ - + @@ -66,7 +65,7 @@ - + @@ -76,34 +75,23 @@ - + - + - - - + + + - - - - - - - - - - - - + diff --git a/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php b/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php index ecf5b352c..86a5c3ada 100644 --- a/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php +++ b/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php @@ -61,12 +61,6 @@ class SmartyParser extends Smarty implements ParserInterface { // The default HTTP status $this->status = 200; - - // Register translation function 'intl' - $this->registerPlugin('function', 'intl', array($this, 'theliaTranslate')); - - // Register Thelia modules inclusion function 'thelia_module' - $this->registerPlugin('function', 'thelia_module', array($this, 'theliaModule')); } public function setTemplate($template_path_from_template_base) { @@ -94,41 +88,6 @@ class SmartyParser extends Smarty implements ParserInterface { return $this->fetch($realTemplateName); } - /** - * Process translate function - * - * @param unknown $params - * @param unknown $smarty - * @return string - */ - public function theliaTranslate($params, &$smarty) - { - if (isset($params['l'])) { - $string = str_replace('\'', '\\\'', $params['l']); - } - else { - $string = ''; - } - - // TODO - - return "[$string]"; - } - - - /** - * Process theliaModule template inclusion function - * - * @param unknown $params - * @param unknown $smarty - * @return string - */ - public function theliaModule($params, &$smarty) - { - // TODO - return ""; - } - /** * * This method must return a Symfony\Component\HttpFoudation\Response instance or the content of the response