RouterResolver   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 4
c 3
b 0
f 1
lcom 0
cbo 1
dl 0
loc 43
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A resolve() 0 19 3
1
<?php
2
/**
3
 * @file
4
 * Contains \NotAFramework\App\Http\RouterResolver.
5
 */
6
7
namespace NotAFramework\App\Http;
8
9
use League\Container\Container;
10
use Phroute\Phroute\HandlerResolverInterface;
11
12
class RouterResolver implements HandlerResolverInterface
13
{
14
    /**
15
     * The dependency injection container.
16
     *
17
     * @var Container
18
     */
19
    private $container;
20
21
    /**
22
     * Create a new RouterResolver instance.
23
     *
24
     * @param Container $container
25
     *   Dependency injection container.
26
     */
27
    public function __construct(Container $container)
28
    {
29
        $this->container = $container;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function resolve($handler)
36
    {
37
        // Only attempt to resolve uninstantiated objects.
38
        if (is_array($handler) && is_string($handler[0])) {
39
            // Retrieve the route handler class from the dependency injection
40
            // container. This ensures that the instantiated handler class
41
            // receives all of the correct dependencies.
42
            $handler_object = $this->container->get($handler[0]);
43
44
            // Manually set the response and request dependencies.
45
            $handler_object->setRequest($this->container->get('Symfony\Component\HttpFoundation\Request'));
46
            $handler_object->setResponse($this->container->get('Symfony\Component\HttpFoundation\Response'));
47
48
            // Pass the object back.
49
            $handler[0] = $handler_object;
50
        }
51
52
        return $handler;
53
    }
54
}
55