Removed AdminSmartyParser, to use directly SmartyParser
This commit is contained in:
@@ -37,15 +37,23 @@ use Symfony\Component\DependencyInjection\ContainerAware;
|
|||||||
* @author Franck Allimant <franck@cqfdev.fr>
|
* @author Franck Allimant <franck@cqfdev.fr>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class BaseAdminController extends ContainerAware
|
class BaseAdminController
|
||||||
{
|
{
|
||||||
protected function render($templateName, $args = array()) {
|
protected $parser;
|
||||||
|
|
||||||
$parser = $this->container->get('thelia.admin.parser');
|
public function __construct($parser) {
|
||||||
|
|
||||||
|
$this->parser = $parser;
|
||||||
|
|
||||||
|
// FIXME: should be red from config
|
||||||
|
$this->parser->setTemplate('admin/default');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function render($templateName, $args = array()) {
|
||||||
|
|
||||||
$args = array('lang' => 'fr');
|
$args = array('lang' => 'fr');
|
||||||
|
|
||||||
return $parser->render($templateName, $args);
|
return $this->parser->render($templateName, $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function indexAction()
|
public function indexAction()
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
<?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\Admin\Template;
|
|
||||||
|
|
||||||
use Thelia\Core\Template\SmartyParser;
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
||||||
|
|
||||||
// smarty configuration
|
|
||||||
class AdminSmartyParser extends SmartyParser
|
|
||||||
{
|
|
||||||
public function __construct(ContainerInterface $container, $template = false)
|
|
||||||
{
|
|
||||||
$this->template = $template == false ? 'admin/default' : $template;
|
|
||||||
|
|
||||||
parent::__construct($container, $template);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function render($realTemplateName, $parameters) {
|
|
||||||
|
|
||||||
$this->assign($parameters);
|
|
||||||
|
|
||||||
return $this->fetch($realTemplateName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
@@ -36,15 +36,9 @@
|
|||||||
<argument type="service" id="service_container"/>
|
<argument type="service" id="service_container"/>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="thelia.parser" class="Thelia\Core\Template\SmartyParser">
|
<service id="thelia.parser" class="Thelia\Core\Template\SmartyParser" scope="request">
|
||||||
<argument type="service" id="service_container"/>
|
<argument type="service" id="request" />
|
||||||
<call method="setLoopList">
|
<argument type="service" id="event_dispatcher"/>
|
||||||
<argument>%tpex.loop%</argument>
|
|
||||||
</call>
|
|
||||||
</service>
|
|
||||||
|
|
||||||
<service id="thelia.admin.parser" class="Thelia\Admin\Template\AdminSmartyParser">
|
|
||||||
<argument type="service" id="service_container"/>
|
|
||||||
<call method="setLoopList">
|
<call method="setLoopList">
|
||||||
<argument>%tpex.loop%</argument>
|
<argument>%tpex.loop%</argument>
|
||||||
</call>
|
</call>
|
||||||
|
|||||||
@@ -20,8 +20,8 @@
|
|||||||
|
|
||||||
<service id="controller.default" class="Thelia\Controller\DefaultController"/>
|
<service id="controller.default" class="Thelia\Controller\DefaultController"/>
|
||||||
|
|
||||||
<service id="thelia.admin.base_controller" class="Thelia\Admin\Controller\BaseAdminController">
|
<service id="thelia.admin.base_controller" class="Thelia\Admin\Controller\BaseAdminController" scope="request">
|
||||||
<argument type="service" id="service_container"/>
|
<argument type="service" id="thelia.parser"/>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="matcher.default" class="Thelia\Routing\Matcher\DefaultMatcher">
|
<service id="matcher.default" class="Thelia\Routing\Matcher\DefaultMatcher">
|
||||||
|
|||||||
@@ -5,6 +5,6 @@
|
|||||||
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
|
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
|
||||||
|
|
||||||
<route id="admin" path="/admin">
|
<route id="admin" path="/admin">
|
||||||
<default key="_controller">Thelia\Admin\Controller\BaseAdminController::indexAction</default>
|
<default key="_controller">thelia.admin.base_controller:indexAction</default>
|
||||||
</route>
|
</route>
|
||||||
</routes>
|
</routes>
|
||||||
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
namespace Thelia\Core\Template;
|
namespace Thelia\Core\Template;
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use \Symfony\Component\HttpFoundation\Request;
|
||||||
|
use \Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
|
|
||||||
use \Smarty;
|
use \Smarty;
|
||||||
|
|
||||||
@@ -19,9 +20,9 @@ class SmartyParser extends Smarty implements ParserInterface {
|
|||||||
|
|
||||||
public $plugins = array();
|
public $plugins = array();
|
||||||
|
|
||||||
protected $container;
|
protected $request, $dispatcher;
|
||||||
|
|
||||||
protected $template = "smarty-sample";
|
protected $template = "";
|
||||||
|
|
||||||
protected $status = 200;
|
protected $status = 200;
|
||||||
|
|
||||||
@@ -30,13 +31,15 @@ class SmartyParser extends Smarty implements ParserInterface {
|
|||||||
protected $asset_manager = null; // Lazy loading
|
protected $asset_manager = null; // Lazy loading
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Symfony\Component\DependencyInjection\ContainerInterface
|
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||||
|
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
|
||||||
*/
|
*/
|
||||||
public function __construct(ContainerInterface $container, $template = false)
|
public function __construct(Request $request, EventDispatcherInterface $dispatcher, $template = false)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->container = $container;
|
$this->request = $request;
|
||||||
|
$this->dispatcher = $dispatcher;
|
||||||
|
|
||||||
// Configure basic Smarty parameters
|
// Configure basic Smarty parameters
|
||||||
|
|
||||||
@@ -46,9 +49,7 @@ class SmartyParser extends Smarty implements ParserInterface {
|
|||||||
$cache_dir = THELIA_ROOT . 'cache/smarty/cache';
|
$cache_dir = THELIA_ROOT . 'cache/smarty/cache';
|
||||||
if (! is_dir($cache_dir)) @mkdir($cache_dir, 0777, true);
|
if (! is_dir($cache_dir)) @mkdir($cache_dir, 0777, true);
|
||||||
|
|
||||||
if ($template != false) $this->template = $template;
|
$this->setTemplate($template != false ? $template : 'smarty-sample');
|
||||||
|
|
||||||
$this->setTemplateDir(THELIA_TEMPLATE_DIR.$this->template);
|
|
||||||
|
|
||||||
$this->setCompileDir($compile_dir);
|
$this->setCompileDir($compile_dir);
|
||||||
$this->setCacheDir($cache_dir);
|
$this->setCacheDir($cache_dir);
|
||||||
@@ -71,6 +72,31 @@ class SmartyParser extends Smarty implements ParserInterface {
|
|||||||
$this->registerPlugin('function', 'thelia_module', array($this, 'theliaModule'));
|
$this->registerPlugin('function', 'thelia_module', array($this, 'theliaModule'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setTemplate($template_path_from_template_base) {
|
||||||
|
|
||||||
|
$this->template = $template_path_from_template_base;
|
||||||
|
|
||||||
|
$this->setTemplateDir(THELIA_TEMPLATE_DIR.$this->template);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTemplate() {
|
||||||
|
return $this->template;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a rendered template file
|
||||||
|
*
|
||||||
|
* @param string $realTemplateName the template name (from the template directory)
|
||||||
|
* @param array $parameters an associative array of names / value pairs
|
||||||
|
* @return string the rendered template text
|
||||||
|
*/
|
||||||
|
public function render($realTemplateName, array $parameters) {
|
||||||
|
|
||||||
|
$this->assign($parameters);
|
||||||
|
|
||||||
|
return $this->fetch($realTemplateName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process {loop name="loop name" type="loop type" ... } ... {/loop} block
|
* Process {loop name="loop name" type="loop type" ... } ... {/loop} block
|
||||||
*
|
*
|
||||||
@@ -405,16 +431,14 @@ class SmartyParser extends Smarty implements ParserInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $class->newInstance(
|
return $class->newInstance(
|
||||||
$this->container->get('request'),
|
$this->request,
|
||||||
$this->container->get('event_dispatcher')
|
$this->dispatcher
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getTemplateFilePath()
|
protected function getTemplateFilePath()
|
||||||
{
|
{
|
||||||
$request = $this->container->get('request');
|
$file = $this->request->attributes->get('_view');
|
||||||
|
|
||||||
$file = $request->attributes->get('_view');
|
|
||||||
|
|
||||||
$fileName = THELIA_TEMPLATE_DIR . rtrim($this->template, "/") . "/" . $file . ".html";
|
$fileName = THELIA_TEMPLATE_DIR . rtrim($this->template, "/") . "/" . $file . ".html";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user