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

VersionExclusionListener   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A onKernelRequest() 0 18 4
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