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

ControllerResolver::getController()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 1
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