custom/plugins/SwpaBackup/src/Subscriber/Kernel/RequestSubscriber.php line 38

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Swpa\SwpaBackup\Subscriber\Kernel;
  3. use Swpa\SwpaBackup\Service\Config;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpFoundation\RedirectResponse;
  6. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  7. use Symfony\Component\HttpKernel\KernelEvents;
  8. /**
  9.  * subscribe request
  10.  *
  11.  * @package Swpa\ProductType
  12.  * @license See COPYING.txt for license details
  13.  * @author  swpa <info@swpa.dev>
  14.  */
  15. class RequestSubscriber implements EventSubscriberInterface
  16. {
  17.     /**
  18.      * @var Config
  19.      */
  20.     protected $config;
  21.     public function __construct(Config $config)
  22.     {
  23.         $this->config $config;
  24.     }
  25.     public static function getSubscribedEvents(): array
  26.     {
  27.         return [
  28.             KernelEvents::REQUEST => ['onKernelRequest'9999],
  29.         ];
  30.     }
  31.     public function onKernelRequest(GetResponseEvent $event): void
  32.     {
  33.         if (!$this->config->isMaintenanceModeEnabled()) {
  34.             return;
  35.         }
  36.         // TODO detect
  37.         $request $event->getRequest();
  38.         if (stripos($request->getRequestUri(), 'maintenance') === false) {
  39.             $event->setResponse(new RedirectResponse('/maintenance/index'));
  40.         }
  41.     }
  42. }