From e760cc28aad7274b5cb5e3f83ee41234b5bf7bf0 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Fri, 8 Nov 2013 11:48:08 +0100 Subject: [PATCH] end controller refactor --- core/lib/Thelia/Controller/BaseController.php | 35 +++++++++++++------ .../Controller/Front/BaseFrontController.php | 19 +++++----- web/test_to_remove/admin-stats.json | 25 ------------- 3 files changed, 32 insertions(+), 47 deletions(-) delete mode 100644 web/test_to_remove/admin-stats.json diff --git a/core/lib/Thelia/Controller/BaseController.php b/core/lib/Thelia/Controller/BaseController.php index fcfb0b910..a8f7b3a63 100755 --- a/core/lib/Thelia/Controller/BaseController.php +++ b/core/lib/Thelia/Controller/BaseController.php @@ -56,7 +56,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * @author Manuel Raynaud */ -class BaseController extends ContainerAware +abstract class BaseController extends ContainerAware { /** @@ -359,15 +359,28 @@ class BaseController extends ContainerAware } /** - * - * return an instance of SmartyParser - * - * Caution : maybe there is still not default template defined. - * - * @return ParserInterface instance parser + * @return a ParserInterface instance parser */ - protected function getParser() - { - return $this->container->get("thelia.parser"); - } + abstract protected function getParser($template = null); + + /** + * Render the given template, and returns the result as an Http Response. + * + * @param $templateName the complete template name, with extension + * @param array $args the template arguments + * @param int $status http code status + * @return \Thelia\Core\HttpFoundation\Response + */ + abstract protected function render($templateName, $args = array(), $status = 200); + + /** + * Render the given template, and returns the result as a string. + * + * @param $templateName the complete template name, with extension + * @param array $args the template arguments + * @param null $templateDir + * + * @return string + */ + abstract protected function renderRaw($templateName, $args = array(), $templateDir = null); } diff --git a/core/lib/Thelia/Controller/Front/BaseFrontController.php b/core/lib/Thelia/Controller/Front/BaseFrontController.php index 003db36c4..124a91296 100755 --- a/core/lib/Thelia/Controller/Front/BaseFrontController.php +++ b/core/lib/Thelia/Controller/Front/BaseFrontController.php @@ -24,10 +24,13 @@ namespace Thelia\Controller\Front; use Symfony\Component\Routing\Router; use Thelia\Controller\BaseController; +use Thelia\Core\HttpFoundation\Response; +use Thelia\Core\Security\Exception\AuthenticationException; use Thelia\Core\Template\TemplateHelper; use Thelia\Model\AddressQuery; use Thelia\Model\ConfigQuery; use Thelia\Model\ModuleQuery; +use Thelia\Tools\Redirect; use Thelia\Tools\URL; class BaseFrontController extends BaseController @@ -119,7 +122,7 @@ class BaseFrontController extends BaseController * @param array $args the template arguments * @param null $templateDir * - * @return \Thelia\Core\HttpFoundation\Response + * @return string */ protected function renderRaw($templateName, $args = array(), $templateDir = null) { @@ -138,16 +141,10 @@ class BaseFrontController extends BaseController )); // Render the template. - try { - $data = $this->getParser($templateDir)->render($templateName, $args); - return $data; - } catch (AuthenticationException $ex) { - // User is not authenticated, and templates requires authentication -> redirect to login page - Redirect::exec(URL::getInstance()->absoluteUrl($ex->getLoginTemplate())); - } catch (AuthorizationException $ex) { - // User is not allowed to perform the required action. Return the error page instead of the requested page. - return $this->errorPage($this->getTranslator()->trans("Sorry, you are not allowed to perform this action."), 403); - } + $data = $this->getParser($templateDir)->render($templateName, $args); + + return $data; + } } diff --git a/web/test_to_remove/admin-stats.json b/web/test_to_remove/admin-stats.json deleted file mode 100644 index 220b140c4..000000000 --- a/web/test_to_remove/admin-stats.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "title" : "Stats on September 2013", - "series" : [ - { - "datas" : [[0,10.00],[1,200.00],[2,5.00],[3,2.75],[4,20.30],[5,14.09],[6,5],[7,23],[8,5],[9,42],[10,0],[11,4],[12,78],[13,75],[14,70],[15,65],[16,102],[17,50],[18,27],[19,35],[20,37],[21,29],[22,56],[23,52],[24,12],[25,6],[26,82],[27,32],[28,15],[29,50],[30,42]], - "color" : "#adadad" - }, - { - "datas" : [[0,2],[1,5],[2,5],[3,7],[4,8],[5,9],[6,5],[7,2],[8,5],[9,4],[10,0],[11,4],[12,7],[13,7],[14,7],[15,6],[16,1],[17,5],[18,2],[19,3],[20,3],[21,2],[22,5],[23,5],[24,1],[25,6],[26,8],[27,3],[28,1],[29,5],[30,4]], - "color" : "#f39922" - }, - { - "datas" : [[0,15],[1,20],[2,1],[3,1],[4,2],[5,3]], - "color" : "#5cb85c" - }, - { - "datas" : [[0,45],[1,40],[2,41],[3,41],[4,42],[5,43]], - "color" : "#5bc0de" - }, - { - "datas" : [[0,25],[1,20],[2,21],[3,21],[4,22],[5,23]], - "color" : "#d9534f" - } - ] -}