- //No route matched
- } catch (ResourceNotFoundException $e) {
- //Unset name and context
- unset($name, $context);
- }
- }
-
- //With login target path option
- if (!empty($loginPath = $this->options['login_path'])) {
- //With path
- if ($loginPath[0] == '/') {
- //Create login path request instance
- $req = Request::create($loginPath);
-
- //Get login path pathinfo
- $path = $req->getPathInfo();
-
- //Remove script name
- $path = str_replace($request->getScriptName(), '', $path);
-
- //Try with login path path
- try {
- //Save old context
- $oldContext = $this->router->getContext();
-
- //Force clean context
- //XXX: prevent MethodNotAllowedException on GET only routes because our context method is POST
- //XXX: see vendor/symfony/routing/Matcher/Dumper/CompiledUrlMatcherTrait.php +42
- $this->router->setContext(new RequestContext());
-
- //Retrieve route matching path
- $route = $this->router->match($path);
-
- //Reset context
- $this->router->setContext($oldContext);
-
- //Clear old context
- unset($oldContext);
-
- //With route name
- if ($name = $route['_route']) {
- //Remove route and controller from route defaults
- unset($route['_route'], $route['_controller'], $route['_canonical_route']);
-
- //Generate url
- $url = $this->router->generate($name, $extra+$route);
-
- //Return redirect to url response
- return new RedirectResponse($url, 302);
- }
- //No route matched
- } catch (ResourceNotFoundException $e) {
- //Unset default path, name and route
- unset($loginPath, $name, $route);
- }
- //With route name
- } else {
- //Try with login path route
- try {
- //Retrieve route matching path
- $url = $this->router->generate($loginPath, $extra);
-
- //Return redirect to url response
- return new RedirectResponse($url, 302);
- //Route not found, missing parameter or invalid parameter
- } catch (RouteNotFoundException|MissingMandatoryParametersException|InvalidParameterException $e) {
- //Unset default path and url
- unset($loginPath, $url);
- }