3 namespace Rapsys\AirBundle\Security
;
5 use Symfony\Component\HttpFoundation\Request
;
6 use Symfony\Component\HttpFoundation\Response
;
7 use Symfony\Component\Security\Core\Exception\AccessDeniedException
;
8 use Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface
;
9 use Symfony\Component\DependencyInjection\ContainerInterface
;
10 use Symfony\Component\Routing\RouterInterface
;
11 use Symfony\Component\Translation\TranslatorInterface
;
14 class AccessDeniedHandler
implements AccessDeniedHandlerInterface
{
21 //Environment instance
22 protected $environment;
25 protected $translator;
30 public function __construct(ContainerInterface
$container, Environment
$environment, RouterInterface
$router, TranslatorInterface
$translator, string $alias = 'rapsys_air') {
32 $this->config
= $container->getParameter($alias);
35 $this->translator
= $translator;
38 $this->environment
= $environment;
42 'copy_long' => $translator->trans($this->config
['copy']['long']),
43 'copy_short' => $translator->trans($this->config
['copy']['short']),
44 'site_ico' => $this->config
['site']['ico'],
45 'site_logo' => $this->config
['site']['logo'],
46 'site_png' => $this->config
['site']['png'],
47 'site_svg' => $this->config
['site']['svg'],
48 'site_title' => $translator->trans($this->config
['site']['title']),
49 'site_url' => $router->generate($this->config
['site']['url'])
56 public function handle(Request
$request, AccessDeniedException
$exception) {
58 $section = $this->translator
->trans('Access denied');
61 $title = $section.' - '.$this->translator
->trans($this->config
['site']['title']);
64 //XXX: we assume that it's already translated
65 $message = $exception->getMessage();
69 $this->environment
->render(
70 '@RapsysAir/security/denied.html.twig',
73 'section' => $section,