vendor/contao/core-bundle/src/EventListener/BypassMaintenanceListener.php line 42

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of Contao.
  5.  *
  6.  * (c) Leo Feyer
  7.  *
  8.  * @license LGPL-3.0-or-later
  9.  */
  10. namespace Contao\CoreBundle\EventListener;
  11. use Contao\CoreBundle\Security\Authentication\Token\TokenChecker;
  12. use Symfony\Component\HttpKernel\Event\RequestEvent;
  13. /**
  14.  * @internal
  15.  */
  16. class BypassMaintenanceListener
  17. {
  18.     /**
  19.      * @var TokenChecker
  20.      */
  21.     private $tokenChecker;
  22.     /**
  23.      * @var string
  24.      */
  25.     private $requestAttribute;
  26.     public function __construct(TokenChecker $tokenCheckerstring $requestAttribute '_bypass_maintenance')
  27.     {
  28.         $this->tokenChecker $tokenChecker;
  29.         $this->requestAttribute $requestAttribute;
  30.     }
  31.     /**
  32.      * Adds the request attribute to the request.
  33.      */
  34.     public function __invoke(RequestEvent $event): void
  35.     {
  36.         if (!$this->tokenChecker->hasBackendUser()) {
  37.             return;
  38.         }
  39.         $request $event->getRequest();
  40.         $request->attributes->set($this->requestAttributetrue);
  41.     }
  42. }