VersionExclusionListener::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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