<?php
declare(strict_types=1);
namespace Lnb\Shopware6\LnbRuleCondition\Subscriber;
use Lnb\Shopware6\LnbRuleCondition\Context\RequestScope;
use Shopware\Core\System\SalesChannel\Event\SalesChannelContextCreatedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RequestStack;
class SalesChannelContextCreatedSubscriber implements EventSubscriberInterface
{
private RequestStack $requestStack;
public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}
public static function getSubscribedEvents(): array
{
return [
SalesChannelContextCreatedEvent::class => 'onSalesChannelContextCreated',
];
}
public function onSalesChannelContextCreated(SalesChannelContextCreatedEvent $event): void
{
$event->getContext()->addExtension('lnbRequestScope', new RequestScope($this->requestStack));
}
}