Completed
Push — master ( e075d7...094677 )
by Maxime
10:19
created

ExpendableRouteServiceProvider::mapApiRoutes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
ccs 0
cts 0
cp 0
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
crap 2
1
<?php namespace Distilleries\Expendable;
2
3
use Distilleries\Expendable\Http\Router\Router;
4
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
5
6
class ExpendableRouteServiceProvider extends ServiceProvider
7
{
8
9
    protected $router;
10
    /**
11
     * This namespace is applied to your controller routes.
12
     *
13
     * In addition, it is set as the URL generator's root namespace.
14
     *
15
     * @var string
16
     */
17
    protected $namespace = 'Distilleries\Expendable\Http\Controllers';
18
19
20
21
    /**
22
     * Define your route model bindings, pattern filters, etc.
23 668
     *
24
     * @return void
25 668
     */
26
    public function boot()
27 501
    {
28
        parent::boot();
29
    }
30
31
    /**
32
     * Define the routes for the application.
33
     *
34
     * @return void
35
     */
36
    public function map()
37 668
    {
38
        $this->mapWebRoutes();
39 668
40 668
        $this->mapApiRoutes();
41 501
42
        //
43
    }
44
45
46
47
    /**
48
     * Register the service provider.
49
     *
50
     * @return void
51
     */
52
    public function register()
53
    {
54
55
        $this->registerRouter();
56
57
    }
58
59
60
    protected function registerRouter(){
61
62
        $this->app['router'] = $this->app->share(function($app)
63
        {
64
            $router = new Router($app['events'], $app);
65
         
66
            return $router;
67
        });
68
    }
69
70
71
    /**
72
     * Define the "web" routes for the application.
73
     *
74
     * These routes all receive session state, CSRF protection, etc.
75
     *
76
     * @return void
77
     */
78
    protected function mapWebRoutes()
79
    {
80
81
        \Route::group([
82
            'middleware' => 'web',
83
            'namespace'  => $this->namespace,
84
        ], function ($router) {
85
86
            require __DIR__ . '/../routes/web.php';
87
        });
88
    }
89
90
    /**
91
     * Define the "api" routes for the application.
92
     *
93
     * These routes are typically stateless.
94
     *
95
     * @return void
96
     */
97
    protected function mapApiRoutes()
98
    {
99
        \Route::group([
100
            'middleware' => 'api',
101
            'namespace'  => $this->namespace,
102
            'prefix'     => 'api',
103
        ], function ($router) {
104
            require __DIR__ . '/../routes/api.php';
105
        });
106
    }
107
}
108