Completed
Push — master ( 7a1429...168b0d )
by Chris
02:39
created

RoutingService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B register() 0 31 3
1
<?php
2
namespace Darya\Service\Provider;
3
4
use Darya\Routing\Router;
5
use Darya\Service\Contracts\Container;
6
use Darya\Service\Contracts\Provider;
7
8
/**
9
 * A service provider that provides a configured router.
10
 * 
11
 * @author Chris Andrew <[email protected]>
12
 */
13
class RoutingService implements Provider
14
{
15
    public function register(Container $container)
16
    {
17
        $container->register(array(
18
            'Darya\Routing\Router' => function ($container) {
19
            	$config = $container->config;
20
            	
21
                $routes = $config['routes'] ?: array(
22
                    '/:controller/:action/:params' => null,
23
                    '/:controller/:params' => null,
24
                    '/:action/:params' => null,
25
                    '/' => null
26
                );
27
                
28
                $projectNamespace = $config['project.namespace'] ?: 'Application';
29
                
30
                $defaultNamespace = "{$projectNamespace}\Controllers";
31
                
32
                $router = new Router($routes, array(
33
                    'namespace' => $defaultNamespace
34
                ));
35
                
36
                $router->base($config['base_url']);
37
                
38
                $router->setServiceContainer($container);
39
                
40
                $router->setEventDispatcher($container->resolve('Darya\Events\Dispatchable'));
41
                
42
                return $router;
43
            }
44
        ));
45
    }
46
}
47