/**
* Event handler that renders custom pages in case of a NotFoundHttpException (404)
* or a AccessDeniedHttpException (403).
*
* @param GetResponseForExceptionEvent $event
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
if ('dev' == $this->kernel->getEnvironment()) {
return;
}
$exception = $event->getException();
$this->request->setLocale($this->defaultLocale);
$this->request->setDefaultLocale($this->defaultLocale);
if ($exception instanceof NotFoundHttpException) {
$section = $this->getExceptionSection(404, '404 Error');
$this->core->addNavigationElement($section);
$unifikRequest = $this->generateUnifikRequest($section);
$this->setUnifikRequestAttributes($unifikRequest);
$this->request->setLocale($this->request->attributes->get('_locale', $this->defaultLocale));
$this->request->setDefaultLocale($this->request->attributes->get('_locale', $this->defaultLocale));
$this->entityManager->getRepository('UnifikSystemBundle:Section')->setLocale($this->request->attributes->get('_locale'));
$response = $this->templating->renderResponse('UnifikSystemBundle:Frontend/Exception:404.html.twig', array('section' => $section));
$response->setStatusCode(404);
$event->setResponse($response);
} elseif ($exception instanceof AccessDeniedHttpException) {
$section = $this->getExceptionSection(403, '403 Error');
$this->core->addNavigationElement($section);
$unifikRequest = $this->generateUnifikRequest($section);
$this->setUnifikRequestAttributes($unifikRequest);
$response = $this->templating->renderResponse('UnifikSystemBundle:Frontend/Exception:403.html.twig', array('section' => $section));
$response->setStatusCode(403);
$event->setResponse($response);
}
}