<?php
namespace Nellapp\Bundle\SDKBundle\EventSubscriber;
use Nellapp\Bundle\SDKBundle\Routing\Utils\ChannelMainDomainUtils;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\KernelEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Routing\RouterInterface;
class RequestChannelDomainSubscriber implements EventSubscriberInterface
{
public function __construct(
private ChannelMainDomainUtils $channelMainDomainUtils,
private RouterInterface $router,
)
{
}
public static function getSubscribedEvents(): array
{
return [
KernelEvents::REQUEST => ['__invoke', 32], // keep high priority
];
}
public function __invoke(KernelEvent $event): void
{
$baseDomain = $this->channelMainDomainUtils->getChannelDomainFromRequest();
$this->channelMainDomainUtils->applyChannelDomainToContext($this->router, $baseDomain);
}
}