end controller refactor
This commit is contained in:
@@ -56,7 +56,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user