Completed
Push — master ( 03ec6c...0df031 )
by
unknown
12:45 queued 02:44
created

VersionExclusionListener::onKernelRequest()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 4
nc 4
nop 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 FOS\RestBundle\View\ConfigurableViewHandlerInterface;
16
use FOS\RestBundle\View\ViewHandlerInterface;
17
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
18
19
/**
20
 * @internal
21
 */
22
class VersionExclusionListener
23
{
24
    private $viewHandler;
25
26
    public function __construct(ViewHandlerInterface $viewHandler)
27
    {
28
        $this->viewHandler = $viewHandler;
29
    }
30
31
    public function onKernelRequest(GetResponseEvent $event)
32
    {
33
        $request = $event->getRequest();
34
35
        if (!$request->attributes->get(FOSRestBundle::ZONE_ATTRIBUTE, true)) {
36
            return;
37
        }
38
39
        if (!$request->attributes->has('version')) {
40
            return;
41
        }
42
43
        $version = $request->attributes->get('version');
44
45
        if ($this->viewHandler instanceof ConfigurableViewHandlerInterface) {
46
            $this->viewHandler->setExclusionStrategyVersion($version);
47
        }
48
    }
49
}
50