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

RedirectExceptionSubscriber::Redirect()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 5
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
}