Completed
Push — master ( 150272...5e1cd2 )
by Matze
14:28 queued 09:42
created

ControllerResolver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 0 Features 2
Metric Value
wmc 5
c 6
b 0
f 2
lcom 0
cbo 3
dl 0
loc 46
ccs 13
cts 13
cp 1
rs 10

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