From 0582ee637184013142a397118146440127a883b9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Gertz?= Date: Thu, 12 Aug 2021 17:04:34 +0200 Subject: [PATCH] Renamed in Handler --- Security/AccessDeniedHandler.php | 138 ------------------------------- 1 file changed, 138 deletions(-) delete mode 100644 Security/AccessDeniedHandler.php diff --git a/Security/AccessDeniedHandler.php b/Security/AccessDeniedHandler.php deleted file mode 100644 index e4ca036..0000000 --- a/Security/AccessDeniedHandler.php +++ /dev/null @@ -1,138 +0,0 @@ -config = $container->getParameter($alias); - - //Set the translator - $this->translator = $translator; - - //Set the environment - $this->environment = $environment; - - //Set the context - $this->context = [ - 'copy' => [ - 'by' => $translator->trans($this->config['copy']['by']), - 'link' => $this->config['copy']['link'], - 'long' => $translator->trans($this->config['copy']['long']), - 'short' => $translator->trans($this->config['copy']['short']), - 'title' => $this->config['copy']['title'] - ], - 'site' => [ - 'ico' => $this->config['site']['ico'], - 'logo' => $this->config['site']['logo'], - 'png' => $this->config['site']['png'], - 'svg' => $this->config['site']['svg'], - 'title' => $translator->trans($this->config['site']['title']), - 'url' => $router->generate($this->config['site']['url']), - ], - 'canonical' => null, - 'alternates' => [] - ]; - - //Get current locale - #$currentLocale = $router->getContext()->getParameters()['_locale']; - $currentLocale = $requestStack->getCurrentRequest()->getLocale(); - - //Set translator locale - //XXX: allow LocaleSubscriber on the fly locale change for first page - $this->translator->setLocale($currentLocale); - - //Iterate on locales excluding current one - foreach($this->config['locales'] as $locale) { - //Set titles - $titles = []; - - //Iterate on other locales - foreach(array_diff($this->config['locales'], [$locale]) as $other) { - $titles[$other] = $translator->trans($this->config['languages'][$locale], [], null, $other); - } - - //Get context path - $path = $router->getContext()->getPathInfo(); - - //Retrieve route matching path - $route = $router->match($path); - - //Get route name - $name = $route['_route']; - - //Unset route name - unset($route['_route']); - - //With current locale - if ($locale == $currentLocale) { - //Set locale locales context - $this->context['canonical'] = $router->generate($name, ['_locale' => $locale]+$route, UrlGeneratorInterface::ABSOLUTE_URL); - } else { - //Set locale locales context - $this->context['alternates'][] = [ - 'lang' => $locale, - 'absolute' => $router->generate($name, ['_locale' => $locale]+$route, UrlGeneratorInterface::ABSOLUTE_URL), - 'relative' => $router->generate($name, ['_locale' => $locale]+$route), - 'title' => implode('/', $titles), - 'translated' => $translator->trans($this->config['languages'][$locale], [], null, $locale) - ]; - } - } - } - - /** - * {@inheritdoc} - */ - public function handle(Request $request, AccessDeniedException $exception) { - //Set section - $section = $this->translator->trans('Access denied'); - - //Set title - $title = $section.' - '.$this->translator->trans($this->config['site']['title']); - - //Set message - //XXX: we assume that it's already translated - $message = $exception->getMessage(); - - //Render template - return new Response( - $this->environment->render( - '@RapsysAir/security/denied.html.twig', - [ - 'title' => $title, - 'section' => $section, - 'message' => $message - ]+$this->context - ), - 403 - ); - } -} -- 2.41.0