Removed AdminSmartyParser, to use directly SmartyParser

This commit is contained in:
franck
2013-06-19 11:52:55 +02:00
parent f32daae118
commit 9e95f034ec
6 changed files with 56 additions and 76 deletions

View File

@@ -37,15 +37,23 @@ use Symfony\Component\DependencyInjection\ContainerAware;
* @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');
return $parser->render($templateName, $args);
return $this->parser->render($templateName, $args);
}
public function indexAction()

View File

@@ -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);
}
}
?>

View File

@@ -36,15 +36,9 @@
<argument type="service" id="service_container"/>
</service>
<service id="thelia.parser" class="Thelia\Core\Template\SmartyParser">
<argument type="service" id="service_container"/>
<call method="setLoopList">
<argument>%tpex.loop%</argument>
</call>
</service>
<service id="thelia.admin.parser" class="Thelia\Admin\Template\AdminSmartyParser">
<argument type="service" id="service_container"/>
<service id="thelia.parser" class="Thelia\Core\Template\SmartyParser" scope="request">
<argument type="service" id="request" />
<argument type="service" id="event_dispatcher"/>
<call method="setLoopList">
<argument>%tpex.loop%</argument>
</call>

View File

@@ -20,8 +20,8 @@
<service id="controller.default" class="Thelia\Controller\DefaultController"/>
<service id="thelia.admin.base_controller" class="Thelia\Admin\Controller\BaseAdminController">
<argument type="service" id="service_container"/>
<service id="thelia.admin.base_controller" class="Thelia\Admin\Controller\BaseAdminController" scope="request">
<argument type="service" id="thelia.parser"/>
</service>
<service id="matcher.default" class="Thelia\Routing\Matcher\DefaultMatcher">

View File

@@ -5,6 +5,6 @@
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="admin" path="/admin">
<default key="_controller">Thelia\Admin\Controller\BaseAdminController::indexAction</default>
<default key="_controller">thelia.admin.base_controller:indexAction</default>
</route>
</routes>

View File

@@ -2,7 +2,8 @@
namespace Thelia\Core\Template;
use Symfony\Component\DependencyInjection\ContainerInterface;
use \Symfony\Component\HttpFoundation\Request;
use \Symfony\Component\EventDispatcher\EventDispatcherInterface;
use \Smarty;
@@ -19,9 +20,9 @@ class SmartyParser extends Smarty implements ParserInterface {
public $plugins = array();
protected $container;
protected $request, $dispatcher;
protected $template = "smarty-sample";
protected $template = "";
protected $status = 200;
@@ -30,13 +31,15 @@ class SmartyParser extends Smarty implements ParserInterface {
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();
$this->container = $container;
$this->request = $request;
$this->dispatcher = $dispatcher;
// Configure basic Smarty parameters
@@ -46,9 +49,7 @@ class SmartyParser extends Smarty implements ParserInterface {
$cache_dir = THELIA_ROOT . 'cache/smarty/cache';
if (! is_dir($cache_dir)) @mkdir($cache_dir, 0777, true);
if ($template != false) $this->template = $template;
$this->setTemplateDir(THELIA_TEMPLATE_DIR.$this->template);
$this->setTemplate($template != false ? $template : 'smarty-sample');
$this->setCompileDir($compile_dir);
$this->setCacheDir($cache_dir);
@@ -71,6 +72,31 @@ class SmartyParser extends Smarty implements ParserInterface {
$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
*
@@ -405,16 +431,14 @@ class SmartyParser extends Smarty implements ParserInterface {
}
return $class->newInstance(
$this->container->get('request'),
$this->container->get('event_dispatcher')
$this->request,
$this->dispatcher
);
}
protected function getTemplateFilePath()
{
$request = $this->container->get('request');
$file = $request->attributes->get('_view');
$file = $this->request->attributes->get('_view');
$fileName = THELIA_TEMPLATE_DIR . rtrim($this->template, "/") . "/" . $file . ".html";