<?php
declare(strict_types=1);
namespace App\Presentation\Web\FrontOffice\Project\Event\Listener;
use App\Presentation\Web\FrontOffice\Common\Context;
use App\Presentation\Web\FrontOffice\Common\Controller\AbstractFrontOfficeController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\RequestEvent;
/**
* Refreshes front office context based on request method.
*/
final class RefreshContextOnRequest
{
private $context;
public function __construct(Context $context)
{
$this->context = $context;
}
public function onKernelRequest(RequestEvent $requestEvent)
{
$isGetMethod = Request::METHOD_GET === $requestEvent->getRequest()->getMethod();
$isFrontOfficeController = is_subclass_of($requestEvent->getRequest()->attributes->get('_controller'),
AbstractFrontOfficeController::class
);
if ($isGetMethod && $isFrontOfficeController) {
$this->context->refresh();
}
}
}