SilexJSRoutingServiceProvider   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 0
cbo 5
dl 0
loc 32
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 10 3
A boot() 0 11 3
A getDefaults() 0 6 1
1
<?php
2
3
namespace rootLogin\JSRoutingProvider\Provider;
4
5
use rootLogin\JSRoutingProvider\Command\DumpJSCommand;
6
use rootLogin\JSRoutingProvider\Command\DumpRouterCommand;
7
use Silex\Application;
8
use Silex\ServiceProviderInterface;
9
10
class SilexJSRoutingServiceProvider implements ServiceProviderInterface
11
{
12
    public function register(Application $app)
13
    {
14
        foreach ($this->getDefaults() as $key => $value) {
15
            if (!isset($app[$key])) {
16
                $app[$key] = $value;
17
            }
18
        }
19
20
        $app->mount($app['jsrouting.base_url'], new SilexJSRoutingControllerProvider());
21
    }
22
23
    public function boot(Application $app)
24
    {
25
        if(isset($app['console'])) {
26
            $console = $app['console'];
27
            if(get_class($console) == "Saxulum\Console\Console\ConsoleApplication") {
28
                /** @var \Saxulum\Console\Console\ConsoleApplication $console */
29
                $console->add(new DumpJSCommand());
30
                $console->add(new DumpRouterCommand());
31
            }
32
        }
33
    }
34
35
    public function getDefaults() {
36
        return array(
37
            "jsrouting.base_url" => "/",
38
            "jsrouting.exposed_routes" => array(),
39
        );
40
    }
41
}
42