SilexJSRoutingControllerProvider::connect()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 34
rs 8.8571
cc 1
eloc 23
nc 1
nop 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
}