Completed
Push — master ( 365b59...c70c47 )
by Matze
06:43
created

ControllerResolver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 45
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getController() 0 8 1
A getArguments() 0 14 3
1
<?php
2
3
namespace BrainExe\Core\Application;
4
5
use BrainExe\Core\Annotations\Service;
6
use Symfony\Component\DependencyInjection\ServiceLocator;
7
use Symfony\Component\HttpFoundation\Request;
8
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
9
10
/**
11
 * @Service
12
 */
13
class ControllerResolver implements ControllerResolverInterface
14
{
15
    /**
16
     * @var ServiceLocator
17
     */
18
    private $controllers;
19
20
    /**
21
     * @param ServiceLocator $controllers
22
     */
23 2
    public function __construct(ServiceLocator $controllers)
24
    {
25 2
        $this->controllers = $controllers;
26 2
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 1
    public function getController(Request $request)
32
    {
33 1
        list($serviceId, $method) = $request->attributes->get('_controller');
34
35 1
        $service = $this->controllers->get($serviceId);
36
37 1
        return [$service, $method];
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 1
    public function getArguments(Request $request, $controller)
44
    {
45
        $arguments = [
46 1
            $request
47
        ];
48
49 1
        foreach ($request->attributes->all() as $attribute => $value) {
50 1
            if ($attribute[0] !== '_') {
51 1
                $arguments[] = $value;
52
            }
53
        }
54
55 1
        return $arguments;
56
    }
57
}
58