]> Raphaƫl G. Git Repositories - airbundle/blob - Handler/AccessDeniedHandler.php
Add cities and city location tempaltes
[airbundle] / Handler / AccessDeniedHandler.php
1 <?php
2
3 namespace Rapsys\AirBundle\Handler;
4
5 use Symfony\Component\HttpFoundation\Request;
6 use Symfony\Component\Security\Core\Exception\AccessDeniedException;
7 use Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface;
8
9 use Rapsys\AirBundle\RapsysAirBundle;
10 use Rapsys\AirBundle\Controller\AbstractController;
11
12 /**
13 * {@inheritdoc}
14 */
15 class AccessDeniedHandler extends AbstractController implements AccessDeniedHandlerInterface {
16 /**
17 * {@inheritdoc}
18 */
19 public function handle(Request $request, AccessDeniedException $exception) {
20 //Set title
21 $this->context['title'] = $this->translator->trans('Access denied');
22
23 //Set message
24 //XXX: we assume that it's already translated
25 $this->context['message'] = $exception->getMessage();
26
27 //With admin
28 if ($this->isGranted('ROLE_ADMIN')) {
29 //Add trace for admin
30 $this->context['trace'] = $exception->getTraceAsString();
31 }
32
33 //Render template
34 $response = $this->render('@RapsysAir/security/denied.html.twig', $this->context);
35 $response->setStatusCode(403);
36 $response->setEtag(md5($response->getContent()));
37 $response->setPublic();
38 $response->isNotModified($request);
39
40 //Return response
41 return $response;
42 }
43 }