SilexJSRoutingControllerProvider   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B connect() 0 34 1
1
<?php
2
3
namespace rootLogin\JSRoutingProvider\Provider;
4
5
use rootLogin\JSRoutingProvider\JSRoutingProvider;
6
use Silex\Application;
7
use Silex\ControllerProviderInterface;
8
use Symfony\Component\HttpFoundation\Response;
9
10
class SilexJSRoutingControllerProvider implements ControllerProviderInterface
11
{
12
    /**
13
     * @var Application
14
     */
15
    private $app;
16
17
    /**
18
     * @var JSRoutingProvider
19
     */
20
    private $jsrp;
21
22
    public function connect(Application $app)
23
    {
24
        $this->app = $app;
25
        $this->jsrp = new JSRoutingProvider($app);
26
27
        /** @var \Silex\ControllerCollection $controllers */
28
        $controllers = $app['controllers_factory'];
29
		
30
		$controllers->get("/router.js", function() {
31
            return new Response(
32
				$this->jsrp->getJavaScript(), 
33
				200, 
34
				array("Content-Type" => "text/javascript")
35
			);
36
        })->bind("jsrouter")->getRoute()->setOption("expose",true);
37
38
        $controllers->get("/routing.js", function() {
39
            return new Response(
40
				$this->jsrp->getJSwithRoutes(), 
41
				200, 
42
				array("Content-Type" => "text/javascript")
43
			);
44
        })->bind("jsrouting")->getRoute()->setOption("expose",true);
45
		
46
		$controllers->get("/routes.js", function() {
47
            return new Response(
48
				$this->jsrp->getJSRoutes(), 
49
				200, 
50
				array("Content-Type" => "text/javascript")
51
			);
52
        })->bind("jsroutes")->getRoute()->setOption("expose",true);
53
54
        return $controllers;
55
    }
56
}