vendor/sonata-project/user-bundle/src/Action/RequestAction.php line 25

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of the Sonata Project package.
  5.  *
  6.  * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Sonata\UserBundle\Action;
  12. use Sonata\AdminBundle\Admin\Pool;
  13. use Sonata\AdminBundle\Templating\TemplateRegistryInterface;
  14. use Symfony\Component\HttpFoundation\RedirectResponse;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  18. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  19. use Twig\Environment;
  20. final class RequestAction
  21. {
  22.     /**
  23.      * @var Environment
  24.      */
  25.     private $twig;
  26.     /**
  27.      * @var UrlGeneratorInterface
  28.      */
  29.     private $urlGenerator;
  30.     /**
  31.      * @var AuthorizationCheckerInterface
  32.      */
  33.     private $authorizationChecker;
  34.     /**
  35.      * @var Pool
  36.      */
  37.     private $adminPool;
  38.     /**
  39.      * @var TemplateRegistryInterface
  40.      */
  41.     private $templateRegistry;
  42.     public function __construct(
  43.         Environment $twig,
  44.         UrlGeneratorInterface $urlGenerator,
  45.         AuthorizationCheckerInterface $authorizationChecker,
  46.         Pool $adminPool,
  47.         TemplateRegistryInterface $templateRegistry
  48.     ) {
  49.         $this->twig $twig;
  50.         $this->urlGenerator $urlGenerator;
  51.         $this->authorizationChecker $authorizationChecker;
  52.         $this->adminPool $adminPool;
  53.         $this->templateRegistry $templateRegistry;
  54.     }
  55.     public function __invoke(Request $request): Response
  56.     {
  57.         if ($this->authorizationChecker->isGranted('IS_AUTHENTICATED_FULLY')) {
  58.             return new RedirectResponse($this->urlGenerator->generate('sonata_admin_dashboard'));
  59.         }
  60.         return new Response($this->twig->render('@SonataUser/Admin/Security/Resetting/request.html.twig', [
  61.             'base_template' => $this->templateRegistry->getTemplate('layout'),
  62.             'admin_pool' => $this->adminPool,
  63.         ]));
  64.     }
  65. }