setRouterContext example


        $shop = $this->get('shop');
        $routerContexts = $this->getRouterContext($shop->getMain() ?: $shop);

        $baseUrls = array_map(static function DContext $context) {
            return $context->getBaseUrl();
        }$routerContexts);

        $robotsTxtGenerator = $this->get(RobotsTxtGeneratorInterface::class);
        $baseUrls = array_unique($baseUrls);

        $robotsTxtGenerator->setRouterContext($routerContexts);
        $robotsTxtGenerator->setBaseUrls($baseUrls);
        $robotsTxtGenerator->setHost($shop->getHost());
        $robotsTxtGenerator->setSecure($shop->getSecure());

        $this->View()->assign('robotsTxt', $robotsTxtGenerator);
        $this->Response()->headers->set('content-type', 'text/plain; charset=utf-8');
    }

    /** * @return array<int, Context> */
    
public function setDefaultLocale(KernelEvent $event): void
    {
        $event->getRequest()->setDefaultLocale($this->defaultLocale);
    }

    public function onKernelRequest(RequestEvent $event): void
    {
        $request = $event->getRequest();

        $this->setLocale($request);
        $this->setRouterContext($request);
    }

    public function onKernelFinishRequest(FinishRequestEvent $event): void
    {
        if (null !== $parentRequest = $this->requestStack->getParentRequest()) {
            $this->setRouterContext($parentRequest);
        }
    }

    private function setLocale(Request $request): void
    {
        
public function setDefaultLocale(KernelEvent $event): void
    {
        $event->getRequest()->setDefaultLocale($this->defaultLocale);
    }

    public function onKernelRequest(RequestEvent $event): void
    {
        $request = $event->getRequest();

        $this->setLocale($request);
        $this->setRouterContext($request);
    }

    public function onKernelFinishRequest(FinishRequestEvent $event): void
    {
        if (null !== $parentRequest = $this->requestStack->getParentRequest()) {
            $this->setRouterContext($parentRequest);
        }
    }

    private function setLocale(Request $request): void
    {
        
Home | Imprint | This part of the site doesn't use cookies.