public getRedirectToRouteConnected ( ) : string | ||
return | string |
/** * @private * @param MvcEvent $event * @return void */ public function onError(MvcEvent $event) { // Do nothing if no error or if response is not HTTP response if (!$event->getParam('exception') instanceof UnauthorizedExceptionInterface || $event->getResult() instanceof HttpResponse || !$event->getResponse() instanceof HttpResponse) { return; } $router = $event->getRouter(); if ($this->authenticationService->hasIdentity()) { if (!$this->options->getRedirectWhenConnected()) { return; } $redirectRoute = $this->options->getRedirectToRouteConnected(); } else { $redirectRoute = $this->options->getRedirectToRouteDisconnected(); } $uri = $router->assemble([], ['name' => $redirectRoute]); if ($this->options->getAppendPreviousUri()) { $redirectKey = $this->options->getPreviousUriQueryKey(); $previousUri = $event->getRequest()->getUriString(); $uri = $router->assemble([], ['name' => $redirectRoute, 'query' => [$redirectKey => $previousUri]]); } $response = $event->getResponse() ?: new HttpResponse(); $response->getHeaders()->addHeaderLine('Location', $uri); $response->setStatusCode(302); $event->setResponse($response); $event->setResult($response); }
public function testSettersAndGetters() { $redirectStrategyOptions = new RedirectStrategyOptions(['redirect_when_connected' => false, 'redirect_to_route_connected' => 'foo', 'redirect_to_route_disconnected' => 'bar', 'append_previous_uri' => false, 'previous_uri_query_key' => 'redirect-to']); $this->assertFalse($redirectStrategyOptions->getRedirectWhenConnected()); $this->assertEquals('foo', $redirectStrategyOptions->getRedirectToRouteConnected()); $this->assertEquals('bar', $redirectStrategyOptions->getRedirectToRouteDisconnected()); $this->assertFalse($redirectStrategyOptions->getAppendPreviousUri()); $this->assertEquals('redirect-to', $redirectStrategyOptions->getPreviousUriQueryKey()); }