Passed
Push — develop ( d944ff...2efefd )
by Stone
07:19 queued 10s
created

RedirectExceptionSubscriber::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\EventSubscriber\Exception;
4
5
use App\Exception\RedirectException;
6
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
7
use Symfony\Component\HttpFoundation\RedirectResponse;
8
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
9
use Symfony\Component\HttpKernel\KernelEvents;
10
11
12
class RedirectExceptionSubscriber implements EventSubscriberInterface
13
{
14
15
    public static function getSubscribedEvents()
16
    {
17
        return [
18
            KernelEvents::EXCEPTION => 'Redirect'
19
        ];
20
    }
21
22
    /**
23
     * @param GetResponseForExceptionEvent $event
24
     */
25
    public function Redirect(GetResponseForExceptionEvent $event)
26
    {
27
        if ($event->getException() instanceof RedirectException) {
28
            $redirectResponse = new RedirectResponse($event->getException()->getRedirectResponse());
29
            $event->setResponse($redirectResponse);
30
        }
31
    }
32
33
}