From 9e95f034ec6d8030fda660153ae816ac346aeadf Mon Sep 17 00:00:00 2001 From: franck Date: Wed, 19 Jun 2013 11:52:55 +0200 Subject: [PATCH] Removed AdminSmartyParser, to use directly SmartyParser --- .../Admin/Controller/BaseAdminController.php | 16 ++++-- .../Admin/Template/AdminSmartyParser.php | 46 ---------------- core/lib/Thelia/Config/Resources/config.xml | 12 ++--- core/lib/Thelia/Config/Resources/routing.xml | 4 +- .../Thelia/Config/Resources/routing/admin.xml | 2 +- .../lib/Thelia/Core/Template/SmartyParser.php | 52 ++++++++++++++----- 6 files changed, 56 insertions(+), 76 deletions(-) delete mode 100644 core/lib/Thelia/Admin/Template/AdminSmartyParser.php diff --git a/core/lib/Thelia/Admin/Controller/BaseAdminController.php b/core/lib/Thelia/Admin/Controller/BaseAdminController.php index 7812057cc..deca35d33 100644 --- a/core/lib/Thelia/Admin/Controller/BaseAdminController.php +++ b/core/lib/Thelia/Admin/Controller/BaseAdminController.php @@ -37,15 +37,23 @@ use Symfony\Component\DependencyInjection\ContainerAware; * @author Franck Allimant */ -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() diff --git a/core/lib/Thelia/Admin/Template/AdminSmartyParser.php b/core/lib/Thelia/Admin/Template/AdminSmartyParser.php deleted file mode 100644 index ac2ba53b0..000000000 --- a/core/lib/Thelia/Admin/Template/AdminSmartyParser.php +++ /dev/null @@ -1,46 +0,0 @@ -. */ -/* */ -/*************************************************************************************/ - -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); - } -} -?> \ No newline at end of file diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 56d06f96f..bd17daa8d 100644 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -36,15 +36,9 @@ - - - - %tpex.loop% - - - - - + + + %tpex.loop% diff --git a/core/lib/Thelia/Config/Resources/routing.xml b/core/lib/Thelia/Config/Resources/routing.xml index 8f9a335d3..2139ebdd4 100644 --- a/core/lib/Thelia/Config/Resources/routing.xml +++ b/core/lib/Thelia/Config/Resources/routing.xml @@ -20,8 +20,8 @@ - - + + diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 8ef577f13..9df36a90a 100644 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -5,6 +5,6 @@ xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> - Thelia\Admin\Controller\BaseAdminController::indexAction + thelia.admin.base_controller:indexAction \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/SmartyParser.php b/core/lib/Thelia/Core/Template/SmartyParser.php index cbe97121d..16de30d4d 100644 --- a/core/lib/Thelia/Core/Template/SmartyParser.php +++ b/core/lib/Thelia/Core/Template/SmartyParser.php @@ -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";