shouldRedirect example

public function testShouldRedirect(Request $request, bool $shouldRedirect): void
    {
        /* * Usually the resolver could be instantiated in the setUp method, but * we need to be able to set the master-request's config here, since * the resolver reads the whitelist from it. */
        $resolver = new MaintenanceModeResolver($this->getRequestStack($request)new CoreMaintenanceModeResolver(new EventDispatcher()));

        if ($shouldRedirect) {
            static::assertTrue(
                $resolver->shouldRedirect($request),
                'Expected to be redirected to the maintenance page, but shouldRedirect returned false.'
            );
        } else {
            static::assertFalse(
                $resolver->shouldRedirect($request),
                'Didn\'t expect to be redirected to the maintenance page, but shouldRedirect returned true.'
            );
        }
    }

    /** * Tests if the resolver redirects requests from the maintenance page to the shop correctly. * * @dataProvider maintenanceModeInactiveProvider * @dataProvider maintenanceModeActiveProvider */
break;
            case $request->getQuery('__shop') !== null:
                $cookieKey = 'shop';
                $cookieValue = $request->getQuery('__shop');
                break;
            case $request->getPost('__currency') !== null:
                $cookieKey = 'currency';
                $cookieValue = $request->getPost('__currency');
                break;
        }

        if ($cookieKey === 'shop' && $this->shouldRedirect($request$shop)) {
            $repository = $this->get(ModelManager::class)->getRepository(Shop::class);

            $newShop = $repository->getActiveById($cookieValue);

            if ($newShop !== null) {
                $redirectUrl = $this->getNewShopUrl($request$newShop);
                $response->setRedirect($redirectUrl);

                if ($newShop->getBasePath()) {
                    $cookiePath = $newShop->getBasePath();
                } else {
                    
public function before(RequestInterface $request$arguments = null)
    {
        if ($request instanceof IncomingRequest) {
            return;
        }

        $security = Services::security();

        try {
            $security->verify($request);
        } catch (SecurityException $e) {
            if ($security->shouldRedirect() && ! $request->isAJAX()) {
                return redirect()->back()->with('error', $e->getMessage());
            }

            throw $e;
        }
    }

    /** * We don't have anything to do here. * * @param array|null $arguments * * @return void */
'redirectTo' => $request->attributes->get('_route'),
            'redirectParameters' => json_encode($request->attributes->get('_route_params'), \JSON_THROW_ON_ERROR),
        ];

        $redirectResponse = new RedirectResponse($this->router->generate('frontend.account.login.page', $parameters));

        $event->setResponse($redirectResponse);
    }

    public function maintenanceResolver(RequestEvent $event): void
    {
        if ($this->maintenanceModeResolver->shouldRedirect($event->getRequest())) {
            $event->setResponse(
                new RedirectResponse(
                    $this->router->generate('frontend.maintenance.page'),
                    RedirectResponse::HTTP_TEMPORARY_REDIRECT
                )
            );
        }
    }

    public function preventPageLoadingFromXmlHttpRequest(ControllerEvent $event): void
    {
        
Home | Imprint | This part of the site doesn't use cookies.