Completed
Push — master ( a422c7...41ba82 )
by Guilh
09:24
created

ExceptionListener::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the FOSRestBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\RestBundle\EventListener;
13
14
use FOS\RestBundle\FOSRestBundle;
15
use Symfony\Component\HttpFoundation\Request;
16
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
17
use Symfony\Component\HttpKernel\EventListener\ExceptionListener as HttpKernelExceptionListener;
18
use Symfony\Component\HttpKernel\KernelEvents;
19
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
20
21
/**
22
 * ExceptionListener.
23
 *
24
 * @author Ener-Getick <[email protected]>
25
 *
26
 * @internal
27
 */
28
class ExceptionListener extends HttpKernelExceptionListener
29
{
30
    /**
31
     * {@inheritdoc}
32 8
     */
33
    public function onKernelException(GetResponseForExceptionEvent $event)
34 8
    {
35
        $request = $event->getRequest();
36 8
37
        if (!$request->attributes->get(FOSRestBundle::ZONE_ATTRIBUTE, true)) {
38
            return;
39
        }
40 8
41 8
        parent::onKernelException($event);
42
    }
43
44
    /**
45
     * {@inheritdoc}
46 8
     */
47
    public static function getSubscribedEvents()
48
    {
49 8
        return array(
50 8
            KernelEvents::EXCEPTION => array('onKernelException', -100),
51 8
        );
52 8
    }
53 8
54 8
    /**
55
     * {@inheritdoc}
56 8
     */
57
    protected function duplicateRequest(\Exception $exception, Request $request)
58
    {
59
        $attributes = array(
60
            '_controller' => $this->controller,
61
            'exception' => $exception,
62
            'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null,
63
        );
64
        $request = $request->duplicate(null, null, $attributes);
65
        $request->setMethod('GET');
66
67
        return $request;
68
    }
69
}
70