end controller refactor

This commit is contained in:
Manuel Raynaud
2013-11-08 11:48:08 +01:00
parent 41d8fce23b
commit e760cc28aa
3 changed files with 32 additions and 47 deletions

View File

@@ -56,7 +56,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @author Manuel Raynaud <mraynaud@openstudio.fr> * @author Manuel Raynaud <mraynaud@openstudio.fr>
*/ */
class BaseController extends ContainerAware abstract class BaseController extends ContainerAware
{ {
/** /**
@@ -359,15 +359,28 @@ class BaseController extends ContainerAware
} }
/** /**
* * @return a ParserInterface instance parser
* return an instance of SmartyParser
*
* Caution : maybe there is still not default template defined.
*
* @return ParserInterface instance parser
*/ */
protected function getParser() abstract protected function getParser($template = null);
{
return $this->container->get("thelia.parser"); /**
} * 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);
} }

View File

@@ -24,10 +24,13 @@ namespace Thelia\Controller\Front;
use Symfony\Component\Routing\Router; use Symfony\Component\Routing\Router;
use Thelia\Controller\BaseController; use Thelia\Controller\BaseController;
use Thelia\Core\HttpFoundation\Response;
use Thelia\Core\Security\Exception\AuthenticationException;
use Thelia\Core\Template\TemplateHelper; use Thelia\Core\Template\TemplateHelper;
use Thelia\Model\AddressQuery; use Thelia\Model\AddressQuery;
use Thelia\Model\ConfigQuery; use Thelia\Model\ConfigQuery;
use Thelia\Model\ModuleQuery; use Thelia\Model\ModuleQuery;
use Thelia\Tools\Redirect;
use Thelia\Tools\URL; use Thelia\Tools\URL;
class BaseFrontController extends BaseController class BaseFrontController extends BaseController
@@ -119,7 +122,7 @@ class BaseFrontController extends BaseController
* @param array $args the template arguments * @param array $args the template arguments
* @param null $templateDir * @param null $templateDir
* *
* @return \Thelia\Core\HttpFoundation\Response * @return string
*/ */
protected function renderRaw($templateName, $args = array(), $templateDir = null) protected function renderRaw($templateName, $args = array(), $templateDir = null)
{ {
@@ -138,16 +141,10 @@ class BaseFrontController extends BaseController
)); ));
// Render the template. // Render the template.
try {
$data = $this->getParser($templateDir)->render($templateName, $args);
return $data; $data = $this->getParser($templateDir)->render($templateName, $args);
} catch (AuthenticationException $ex) {
// User is not authenticated, and templates requires authentication -> redirect to login page return $data;
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);
}
} }
} }

View File

@@ -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"
}
]
}