Test Failed
Push — master ( 25b8d1...f70cb8 )
by Pavel
03:49
created

CrudsParamConverter::getRouter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace ScayTrase\Api\Cruds\Listener;
4
5
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
6
use Symfony\Component\Routing\RouterInterface;
7
8
final class CrudsParamConverter
9
{
10
    use CrudsRequestCheckerTrait;
11
12
    const PARAMETER_WHITE_LIST = [
13
        'identifier',
14
        'data',
15
        'criteria',
16
        'order',
17
        'limit',
18
        'offset',
19
    ];
20
21
    /** @var  RouterInterface */
22
    private $router;
23
24
    /**
25
     * CrudsParamConverter constructor.
26
     *
27
     * @param RouterInterface $router
28
     */
29
    public function __construct(RouterInterface $router)
30
    {
31
        $this->router = $router;
32
    }
33
34
    public function onCrudRequest(GetResponseEvent $event)
35
    {
36
        if (!$this->checkRequest($event)) {
37
            return;
38
        }
39
40
        $request = $event->getRequest();
41
        foreach (self::PARAMETER_WHITE_LIST as $param) {
42
            $value = $request->get($param);
43
            if (null !== $value) {
44
                $request->attributes->set($param, $value);
45
            }
46
        }
47
    }
48
49
    /** {@inheritdoc} */
50
    protected function getRouter()
51
    {
52
        return $this->router;
53
    }
54
}
55