<?php declare(strict_types=1);
namespace Samson\Routing;
/***
*
* This file is part of the "SAMSON Shop" project.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* (c) 2020
*
***/
use Shopware\Core\Framework\Routing\KernelListenerPriorities;
use Shopware\Core\Framework\Routing\RequestContextResolverInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\KernelEvents;
/**
* Class ContextResolverListener
* @package Samson\Api\Controller
* @author Artur Seitz <artur.seitz@dkd.de>
*/
class ContextResolverListener implements EventSubscriberInterface
{
/** @var RequestContextResolverInterface */
protected $requestContextResolver;
/**
* ContextResolverListener constructor.
* @param RequestContextResolverInterface $requestContextResolver
*/
public function __construct(
RequestContextResolverInterface $requestContextResolver
) {
$this->requestContextResolver = $requestContextResolver;
}
/** {@inheritDoc} */
public static function getSubscribedEvents(): array
{
return [
KernelEvents::CONTROLLER => [
['resolveContext', KernelListenerPriorities::KERNEL_CONTROLLER_EVENT_CONTEXT_RESOLVE],
],
];
}
/**
* KernelEvents::CONTROLLER event listener.
* @param ControllerEvent $event
*/
public function resolveContext(ControllerEvent $event): void
{
$this->requestContextResolver->resolve($event->getRequest());
}
}