Completed
Push — master ( f9dcdb...5d2770 )
by Enrico
02:49
created

ControllerResolver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 25
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getController() 0 13 3
1
<?php
2
namespace uSILEX;
3
4
/*
5
 * inspired to https://api.symfony.com/4.1/Symfony/Component/HttpKernel/Controller/ControllerResolverInterface.html
6
 */
7
8
use uSILEX\Exception\NotFoundHttpException;
9
10
11
Class ControllerResolver implements ControllerResolverInterface
12
{
13
    protected $app;
14
    
15
    
16 5
    public function __construct(Application $app) 
17
    {
18 5
        assert(isset($app['RouteMatcher']));
19
        
20 5
        $this->app = $app;
21 5
    }
22
23 5
    public function getController() : Route
24
    {
25 5
        assert(isset($this->app['request']));
26
        
27 5
        foreach ($this->app->getRoutes() as $route) {
28 4
            if ($matches = $this->app['RouteMatcher']->match($route)) {
29 3
                $this->app['request.matches'] = $matches;
30 3
                $this->app['request.route'] = $route;
31 4
                return $route;
32
            }
33
        }
34
        
35 2
        throw new NotFoundHttpException('Resource controller not found');
36
    }
37
}