<?php declare(strict_types=1);
namespace Swpa\SwpaBackup\Subscriber\Kernel;
use Swpa\SwpaBackup\Service\Config;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
/**
* subscribe request
*
* @package Swpa\ProductType
* @license See COPYING.txt for license details
* @author swpa <info@swpa.dev>
*/
class RequestSubscriber implements EventSubscriberInterface
{
/**
* @var Config
*/
protected $config;
public function __construct(Config $config)
{
$this->config = $config;
}
public static function getSubscribedEvents(): array
{
return [
KernelEvents::REQUEST => ['onKernelRequest', 9999],
];
}
public function onKernelRequest(GetResponseEvent $event): void
{
if (!$this->config->isMaintenanceModeEnabled()) {
return;
}
// TODO detect
$request = $event->getRequest();
if (stripos($request->getRequestUri(), 'maintenance') === false) {
$event->setResponse(new RedirectResponse('/maintenance/index'));
}
}
}