Merge branch 'admin' of github.com:thelia/thelia into admin
Conflicts: core/lib/Thelia/Config/Resources/config.xml
This commit is contained in:
@@ -4,14 +4,24 @@
|
|||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
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">
|
xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd">
|
||||||
|
|
||||||
<testLoops>
|
|
||||||
<testLoop name="equal" class="Thelia\Core\Template\TestLoop\Equal"/>
|
|
||||||
</testLoops>
|
|
||||||
|
|
||||||
<loops>
|
<loops>
|
||||||
<loop class="Thelia\Core\Template\Loop\Category" name="category"/>
|
<loop class="Thelia\Core\Template\Loop\Category" name="category"/>
|
||||||
</loops>
|
</loops>
|
||||||
|
|
||||||
|
|
||||||
|
<filters>
|
||||||
|
<!-- Sample definition
|
||||||
|
<filter class="Thelia\Core\Template\Filter\SomeFilterClass" name="my_filter"/>
|
||||||
|
-->
|
||||||
|
</filters>
|
||||||
|
|
||||||
|
<templateDirectives>
|
||||||
|
<!-- Sample definition
|
||||||
|
<templateDirectives class="Thelia\Core\Template\Filter\SomeFilterClass" name="my_filter"/>
|
||||||
|
-->
|
||||||
|
</templateDirectives>
|
||||||
|
|
||||||
|
|
||||||
<commands>
|
<commands>
|
||||||
<command class="Thelia\Command\CacheClear"/>
|
<command class="Thelia\Command\CacheClear"/>
|
||||||
<command class="Thelia\Command\Install"/>
|
<command class="Thelia\Command\Install"/>
|
||||||
@@ -55,17 +65,24 @@
|
|||||||
<argument type="service" id="request" />
|
<argument type="service" id="request" />
|
||||||
<argument type="service" id="event_dispatcher"/>
|
<argument type="service" id="event_dispatcher"/>
|
||||||
<call method="setLoopList">
|
<call method="setLoopList">
|
||||||
<argument>%tpex.loop%</argument>
|
<argument>%thelia.parser.loops%</argument>
|
||||||
</call>
|
</call>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
|
<service id="smarty.plugin.translation" class="Thelia\Core\Template\Smarty\Plugins\Translation" >
|
||||||
|
<tag name="thelia.parser.register_plugin"/>
|
||||||
|
</service>
|
||||||
|
|
||||||
|
<service id="smarty.plugin.module" class="Thelia\Core\Template\Smarty\Plugins\Module" >
|
||||||
|
<tag name="thelia.parser.register_plugin"/>
|
||||||
|
</service>
|
||||||
|
|
||||||
<service id="http_kernel" class="Thelia\Core\TheliaHttpKernel">
|
<service id="http_kernel" class="Thelia\Core\TheliaHttpKernel">
|
||||||
<argument type="service" id="event_dispatcher" />
|
<argument type="service" id="event_dispatcher" />
|
||||||
<argument type="service" id="service_container" />
|
<argument type="service" id="service_container" />
|
||||||
<argument type="service" id="controller_resolver" />
|
<argument type="service" id="controller_resolver" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
|
|
||||||
<service id="request" scope="request" synthetic="true" />
|
<service id="request" scope="request" synthetic="true" />
|
||||||
|
|
||||||
<service id="service_container" synthetic="true" />
|
<service id="service_container" synthetic="true" />
|
||||||
|
|||||||
@@ -57,9 +57,7 @@ class XmlFileLoader extends FileLoader
|
|||||||
|
|
||||||
$this->parseFilters($xml);
|
$this->parseFilters($xml);
|
||||||
|
|
||||||
$this->parseBaseParams($xml);
|
$this->parseTemplateDirectives($xml);
|
||||||
|
|
||||||
$this->parseTestLoops($xml);
|
|
||||||
|
|
||||||
$this->parseParameters($xml);
|
$this->parseParameters($xml);
|
||||||
|
|
||||||
@@ -112,7 +110,7 @@ class XmlFileLoader extends FileLoader
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$loopConfig = $this->container->getParameter("Tpex.loop");
|
$loopConfig = $this->container->getParameter("Thelia.parser.loops");
|
||||||
} catch (\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException $e) {
|
} catch (\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException $e) {
|
||||||
$loopConfig = array();
|
$loopConfig = array();
|
||||||
}
|
}
|
||||||
@@ -121,7 +119,7 @@ class XmlFileLoader extends FileLoader
|
|||||||
$loopConfig[$loop->getAttributeAsPhp("name")] = $loop->getAttributeAsPhp("class");
|
$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;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$filterConfig = $this->container->getParameter("Tpex.filter");
|
$filterConfig = $this->container->getParameter("Thelia.parser.filters");
|
||||||
} catch (\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException $e) {
|
} catch (\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException $e) {
|
||||||
$filterConfig = array();
|
$filterConfig = array();
|
||||||
}
|
}
|
||||||
@@ -144,7 +142,7 @@ class XmlFileLoader extends FileLoader
|
|||||||
$filterConfig[$filter->getAttributeAsPhp("name")] = $filter->getAttributeAsPhp("class");
|
$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
|
* @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;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$baseParamConfig = $this->container->getParameter("Tpex.baseParam");
|
$baseParamConfig = $this->container->getParameter("Thelia.parser.templateDirectives");
|
||||||
} catch (\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException $e) {
|
} catch (\Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException $e) {
|
||||||
$baseParamConfig = array();
|
$baseParamConfig = array();
|
||||||
}
|
}
|
||||||
@@ -167,30 +165,7 @@ class XmlFileLoader extends FileLoader
|
|||||||
$baseParamConfig[$baseParam->getAttributeAsPhp("name")] = $baseParam->getAttributeAsPhp("class");
|
$baseParamConfig[$baseParam->getAttributeAsPhp("name")] = $baseParam->getAttributeAsPhp("class");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->container->setParameter("Tpex.baseParam", $baseParamConfig);
|
$this->container->setParameter("Thelia.parser.templateDirectives", $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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -10,9 +10,8 @@
|
|||||||
<xsd:complexType name="config">
|
<xsd:complexType name="config">
|
||||||
<xsd:choice minOccurs="0" maxOccurs="unbounded">
|
<xsd:choice minOccurs="0" maxOccurs="unbounded">
|
||||||
<xsd:element name="loops" type="loops" />
|
<xsd:element name="loops" type="loops" />
|
||||||
<xsd:element name="filters" type="filter" />
|
<xsd:element name="filters" type="filters" />
|
||||||
<xsd:element name="baseParams" type="baseParams" />
|
<xsd:element name="templateDirectives" type="templateDirectives" />
|
||||||
<xsd:element name="testLoops" type="testLoops" />
|
|
||||||
<xsd:element name="services" type="services" />
|
<xsd:element name="services" type="services" />
|
||||||
<xsd:element name="parameters" type="parameters"/>
|
<xsd:element name="parameters" type="parameters"/>
|
||||||
<xsd:element name="commands" type="commands"/>
|
<xsd:element name="commands" type="commands"/>
|
||||||
@@ -55,7 +54,7 @@
|
|||||||
</xsd:simpleType>
|
</xsd:simpleType>
|
||||||
|
|
||||||
<xsd:complexType name="loops">
|
<xsd:complexType name="loops">
|
||||||
<xsd:choice minOccurs="1" maxOccurs="unbounded" >
|
<xsd:choice minOccurs="0" maxOccurs="unbounded" >
|
||||||
<xsd:element name="loop" type="loop"/>
|
<xsd:element name="loop" type="loop"/>
|
||||||
</xsd:choice>
|
</xsd:choice>
|
||||||
</xsd:complexType>
|
</xsd:complexType>
|
||||||
@@ -66,7 +65,7 @@
|
|||||||
</xsd:complexType>
|
</xsd:complexType>
|
||||||
|
|
||||||
<xsd:complexType name="commands">
|
<xsd:complexType name="commands">
|
||||||
<xsd:choice minOccurs="1" maxOccurs="unbounded" >
|
<xsd:choice minOccurs="0" maxOccurs="unbounded" >
|
||||||
<xsd:element name="command" type="command"/>
|
<xsd:element name="command" type="command"/>
|
||||||
</xsd:choice>
|
</xsd:choice>
|
||||||
</xsd:complexType>
|
</xsd:complexType>
|
||||||
@@ -76,7 +75,7 @@
|
|||||||
</xsd:complexType>
|
</xsd:complexType>
|
||||||
|
|
||||||
<xsd:complexType name="filters">
|
<xsd:complexType name="filters">
|
||||||
<xsd:choice minOccurs="1" maxOccurs="unbounded">
|
<xsd:choice minOccurs="0" maxOccurs="unbounded">
|
||||||
<xsd:element name="filter" type="filter" />
|
<xsd:element name="filter" type="filter" />
|
||||||
</xsd:choice>
|
</xsd:choice>
|
||||||
</xsd:complexType>
|
</xsd:complexType>
|
||||||
@@ -86,24 +85,13 @@
|
|||||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
</xsd:complexType>
|
</xsd:complexType>
|
||||||
|
|
||||||
<xsd:complexType name="baseParams">
|
<xsd:complexType name="templateDirectives">
|
||||||
<xsd:choice minOccurs="1" maxOccurs="unbounded">
|
<xsd:choice minOccurs="0" maxOccurs="unbounded">
|
||||||
<xsd:element name="baseParam" type="baseParam" />
|
<xsd:element name="templateDirective" type="templateDirective" />
|
||||||
</xsd:choice>
|
</xsd:choice>
|
||||||
</xsd:complexType>
|
</xsd:complexType>
|
||||||
|
|
||||||
<xsd:complexType name="baseParam">
|
<xsd:complexType name="templateDirective">
|
||||||
<xsd:attribute name="class" type="xsd:string" use="required" />
|
|
||||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
|
||||||
</xsd:complexType>
|
|
||||||
|
|
||||||
<xsd:complexType name="testLoops">
|
|
||||||
<xsd:choice minOccurs="1" maxOccurs="unbounded">
|
|
||||||
<xsd:element name="testLoop" type="testLoop" />
|
|
||||||
</xsd:choice>
|
|
||||||
</xsd:complexType>
|
|
||||||
|
|
||||||
<xsd:complexType name="testLoop">
|
|
||||||
<xsd:attribute name="class" type="xsd:string" use="required" />
|
<xsd:attribute name="class" type="xsd:string" use="required" />
|
||||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
</xsd:complexType>
|
</xsd:complexType>
|
||||||
|
|||||||
56
core/lib/Thelia/Core/Template/Smarty/Plugins/Module.php
Normal file
56
core/lib/Thelia/Core/Template/Smarty/Plugins/Module.php
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<?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\Template\Smarty\Plugins;
|
||||||
|
|
||||||
|
|
||||||
|
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
||||||
|
use Thelia\Core\Template\Smarty\SmartyPluginInterface;
|
||||||
|
|
||||||
|
class Module implements SmartyPluginInterface {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process theliaModule template inclusion function
|
||||||
|
*
|
||||||
|
* @param unknown $params
|
||||||
|
* @param unknown $smarty
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function theliaModule($params, &$smarty)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the various smarty plugins hendled by this class
|
||||||
|
*
|
||||||
|
* @return an array of smarty plugin descriptors
|
||||||
|
*/
|
||||||
|
public function getPluginDescriptors()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
new SmartyPluginDescriptor('function', 'module_include', $this, 'theliaModule'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
65
core/lib/Thelia/Core/Template/Smarty/Plugins/Translation.php
Normal file
65
core/lib/Thelia/Core/Template/Smarty/Plugins/Translation.php
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
<?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\Template\Smarty\Plugins;
|
||||||
|
|
||||||
|
|
||||||
|
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
||||||
|
use Thelia\Core\Template\Smarty\SmartyPluginInterface;
|
||||||
|
|
||||||
|
class Translation implements SmartyPluginInterface {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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]";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the various smarty plugins hendled by this class
|
||||||
|
*
|
||||||
|
* @return an array of smarty plugin descriptors
|
||||||
|
*/
|
||||||
|
public function getPluginDescriptors()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
new SmartyPluginDescriptor('function', 'intl', $this, 'theliaTranslate'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -61,12 +61,6 @@ class SmartyParser extends Smarty implements ParserInterface {
|
|||||||
|
|
||||||
// The default HTTP status
|
// The default HTTP status
|
||||||
$this->status = 200;
|
$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) {
|
public function setTemplate($template_path_from_template_base) {
|
||||||
@@ -94,41 +88,6 @@ class SmartyParser extends Smarty implements ParserInterface {
|
|||||||
return $this->fetch($realTemplateName);
|
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
|
* This method must return a Symfony\Component\HttpFoudation\Response instance or the content of the response
|
||||||
|
|||||||
171
core/lib/Thelia/Core/Template/TPex/Parser.php
Normal file
171
core/lib/Thelia/Core/Template/TPex/Parser.php
Normal file
@@ -0,0 +1,171 @@
|
|||||||
|
<?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\Template\TPex;
|
||||||
|
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Thelia\Core\Template\ParserInterface;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
|
||||||
|
use Symfony\Component\Config\ConfigCache;
|
||||||
|
|
||||||
|
use Thelia\Tpex\Tpex;
|
||||||
|
use Thelia\Log\Tlog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Master class of Thelia's parser. The loop mechanism depends of this parser
|
||||||
|
*
|
||||||
|
* From this class all the parser is lunch
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
class Parser implements ParserInterface
|
||||||
|
{
|
||||||
|
const PREFIXE = 'prx';
|
||||||
|
|
||||||
|
const SHOW_TIME = true;
|
||||||
|
const ALLOW_DEBUG = true;
|
||||||
|
const USE_CACHE = true;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var Symfony\Component\DependencyInjection\ContainerInterface
|
||||||
|
*/
|
||||||
|
protected $container;
|
||||||
|
|
||||||
|
protected $content;
|
||||||
|
protected $status = 200;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var Thelia\Tpex\Tpex
|
||||||
|
*/
|
||||||
|
protected $tpex;
|
||||||
|
|
||||||
|
protected $template = "default";
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param type $container
|
||||||
|
*
|
||||||
|
* public function __construct(ContainerBuilder $container)
|
||||||
|
*/
|
||||||
|
public function __construct(ContainerInterface $container)
|
||||||
|
{
|
||||||
|
$this->container = $container;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return Symfony\Component\HttpFoundation\Request
|
||||||
|
*/
|
||||||
|
public function getRequest()
|
||||||
|
{
|
||||||
|
return $this->container->get('request');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return Symfony\Component\EventDispatcher\EventDispatcher
|
||||||
|
*/
|
||||||
|
public function getDispatcher()
|
||||||
|
{
|
||||||
|
return $this->container->get('dispatcher');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This method must return a Symfony\Component\HttpFoudation\Response instance or the content of the response
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function getContent()
|
||||||
|
{
|
||||||
|
$this->loadParser();
|
||||||
|
|
||||||
|
return $this->content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* set $content with the body of the response or the Response object directly
|
||||||
|
*
|
||||||
|
* @param string|Symfony\Component\HttpFoundation\Response $content
|
||||||
|
*/
|
||||||
|
public function setContent($content)
|
||||||
|
{
|
||||||
|
$this->content = $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return type the status of the response
|
||||||
|
*/
|
||||||
|
public function getStatus()
|
||||||
|
{
|
||||||
|
return $this->status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* status HTTP of the response
|
||||||
|
*
|
||||||
|
* @param int $status
|
||||||
|
*/
|
||||||
|
public function setStatus($status)
|
||||||
|
{
|
||||||
|
$this->status = $status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main parser function, load the parser
|
||||||
|
*/
|
||||||
|
public function loadParser()
|
||||||
|
{
|
||||||
|
$content = $this->openFile($this->getRequest());
|
||||||
|
|
||||||
|
$tpex = $this->container->get("template");
|
||||||
|
|
||||||
|
$tpex->setBaseDir(THELIA_TEMPLATE_DIR . rtrim($this->template, "/") . "/");
|
||||||
|
$tpex->setContent($content);
|
||||||
|
|
||||||
|
$this->setContent($tpex->execute());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function openFile(Request $request)
|
||||||
|
{
|
||||||
|
$file = $request->attributes->get('_view');
|
||||||
|
$fileName = THELIA_TEMPLATE_DIR . rtrim($this->template, "/") . "/" . $file . ".html";
|
||||||
|
if (file_exists($fileName)) {
|
||||||
|
$content = file_get_contents($fileName);
|
||||||
|
} else {
|
||||||
|
throw new ResourceNotFoundException(sprintf("%s file not found in %s template", $file, $this->template));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user