X-Git-Url: https://git.rapsys.eu/.gitweb.cgi/userbundle/blobdiff_plain/0f917988b2103a83699d4e4575f7a75aade9e5df..be90ff0448f23198efda2b575744cd160088b94d:/Handler/LogoutSuccessHandler.php diff --git a/Handler/LogoutSuccessHandler.php b/Handler/LogoutSuccessHandler.php deleted file mode 100644 index de862d5..0000000 --- a/Handler/LogoutSuccessHandler.php +++ /dev/null @@ -1,186 +0,0 @@ -config = $container->getParameter(self::getAlias()); - - //Set target url - $this->targetUrl = $targetUrl; - - //Set router - $this->router = $router; - } - - /** - * {@inheritdoc} - */ - public function onLogoutSuccess(Request $request) { - //Retrieve logout route - $logout = $request->get('_route'); - - //Extract and process referer - if (($referer = $request->headers->get('referer'))) { - //Create referer request instance - $req = Request::create($referer); - - //Get referer path - $path = $req->getPathInfo(); - - //Get referer query string - $query = $req->getQueryString(); - - //Remove script name - $path = str_replace($request->getScriptName(), '', $path); - - //Try with referer 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); - - //Without logout route name - if (($name = $route['_route']) != $logout) { - //Remove route and controller from route defaults - unset($route['_route'], $route['_controller'], $route['_canonical_route']); - - //Generate url - $url = $this->router->generate($name, $route); - - //Return generated route - return new RedirectResponse($url, 302); - //With logout route name - } else { - //Unset referer and route - unset($referer, $route); - } - //No route matched - } catch (ResourceNotFoundException $e) { - //Unset referer and route - unset($referer, $route); - } - } - - //With index route from config - if (!empty($name = $this->config['route']['index']['name']) && is_array($context = $this->config['route']['index']['context'])) { - //Without logout route name - if (($name = $route['_route']) != $logout) { - //Try index route - try { - //Generate url - $url = $this->router->generate($name, $context); - - //Return generated route - return new RedirectResponse($url, 302); - //No route matched - } catch (ResourceNotFoundException $e) { - //Unset name and context - unset($name, $context); - } - //With logout route name - } else { - //Unset name and context - unset($name, $context); - } - } - - //Try target url - 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 target url - $route = $this->router->match($this->targetUrl); - - //Reset context - $this->router->setContext($oldContext); - - //Clear old context - unset($oldContext); - - //Without logout route name - if (($name = $route['_route']) != $logout) { - //Remove route and controller from route defaults - unset($route['_route'], $route['_controller'], $route['_canonical_route']); - - //Generate url - $url = $this->router->generate($name, $route); - - //Return generated route - return new RedirectResponse($url, 302); - //With logout route name - } else { - //Unset name and route - unset($name, $route); - } - //Get first route from route collection if / path was not matched - } catch (ResourceNotFoundException $e) { - //Unset name and route - unset($name, $route); - } - - //Throw exception - throw new \RuntimeException('You must provide a valid logout target url or route name'); - } - - /** - * {@inheritdoc} - */ - public function getAlias(): string { - return RapsysUserBundle::getAlias(); - } -}