[Controller] Fix exception handler to recurse on the exception's previous (in some contexts, RedirectException gets wrapped)
This commit is contained in:
parent
ffcf909bda
commit
2164f21834
@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
namespace App\Core;
|
namespace App\Core;
|
||||||
|
|
||||||
|
use App\Util\Common;
|
||||||
use App\Util\Exception\RedirectException;
|
use App\Util\Exception\RedirectException;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
@ -61,7 +62,7 @@ class Controller extends AbstractController implements EventSubscriberInterface
|
|||||||
$controller = $event->getController();
|
$controller = $event->getController();
|
||||||
$request = $event->getRequest();
|
$request = $event->getRequest();
|
||||||
|
|
||||||
$this->vars = ['controler' => $controller, 'request' => $request];
|
$this->vars = ['controler' => $controller, 'request' => $request, 'have_user' => Common::user() !== null];
|
||||||
Event::handle('start_twig_populate_vars', [&$this->vars]);
|
Event::handle('start_twig_populate_vars', [&$this->vars]);
|
||||||
|
|
||||||
$event->stopPropagation();
|
$event->stopPropagation();
|
||||||
@ -100,13 +101,16 @@ class Controller extends AbstractController implements EventSubscriberInterface
|
|||||||
|
|
||||||
public function onKernelException(ExceptionEvent $event)
|
public function onKernelException(ExceptionEvent $event)
|
||||||
{
|
{
|
||||||
if (($except = $event->getThrowable()) instanceof RedirectException) {
|
$except = $event->getThrowable();
|
||||||
if (($redir = $except->redirect_response) != null) {
|
do {
|
||||||
$event->setResponse($redir);
|
if ($except instanceof RedirectException) {
|
||||||
} else {
|
if (($redir = $except->redirect_response) != null) {
|
||||||
$event->setResponse(new RedirectResponse($event->getRequest()->getPathInfo()));
|
$event->setResponse($redir);
|
||||||
|
} else {
|
||||||
|
$event->setResponse(new RedirectResponse($event->getRequest()->getPathInfo()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} while ($except != null && ($except = $except->getPrevious()) != null);
|
||||||
return $event;
|
return $event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user