* @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) */ declare(strict_types=1); namespace PrestaShopBundle\EventListener; use PrestaShop\PrestaShop\Adapter\Shop\Context; use Symfony\Component\HttpKernel\Event\RequestEvent; /** * This subscriber gets context from the legacy context and adds it the request attributes * so you can directly fetch the ShopConstraint on the controller arguments. */ class ShopConstraintListener { /** * @var Context */ private $context; public function __construct(Context $context) { $this->context = $context; } public function onKernelRequest(RequestEvent $event): void { if (!$event->isMasterRequest()) { return; } $shopConstraint = $this->context->getShopConstraint(); $event->getRequest()->attributes->set('shopConstraint', $shopConstraint); } }