Completed
Push — master ( a0f59b...05c571 )
by Elf
05:11
created

RouteServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 74
ccs 22
cts 22
cp 1
rs 10
wmc 3
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 10 1
B map() 0 41 2
1
<?php
2
3
namespace App\Providers;
4
5
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
6
use Illuminate\Support\Facades\Route;
7
8
class RouteServiceProvider extends ServiceProvider
9
{
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 = 'App\Http\Controllers';
18
19
    /**
20
     * Define your route model bindings, pattern filters, etc.
21
     *
22
     * @return void
23
     */
24 1
    public function boot()
25
    {
26 1
        $this->pattern('id', '[0-9]+');
27
28
        $this->bind('admin_user', function ($value) {
29
            return \App\Models\AdminUser::find($value);
30 1
        });
31
32 1
        parent::boot();
33 1
    }
34
35
    /**
36
     * Define the routes for the application.
37
     *
38
     * @return void
39
     */
40 1
    public function map()
41
    {
42
        // Defines all routes in format: `identifier => attributes`.
43
        // If there is no "namespace" in attributes, the default namespace will be `$this->namespace.'\\'.studly_case($identifier)`.
44
        // The routes definitions will be placed in file "routes/{$identifer}.php".
45
        $routes = [
46
            'global' => [
47
                'namespace' => '',
48 1
            ],
49
50
            'site' => [
51 1
                'domain' => config('app.domains.site'),
52 1
                'middleware' => 'web',
53
            ],
54
55
            'admin' => [
56 1
                'domain' => config('app.domains.admin'),
57 1
                'middleware' => 'web',
58
            ],
59
60
            'api' => [
61 1
                'domain' => config('app.domains.api'),
62 1
                'middleware' => 'api',
63
            ],
64
65
            'api-web' => [
66 1
                'domain' => config('app.domains.site'),
67 1
                'prefix' => 'api',
68 1
                'namespace' => 'Site',
69
                'middleware' => ['web', 'api.client'],
70
            ],
71
        ];
72
73 1
        foreach ($routes as $identifier => $attributes) {
74 1
            $attributes['namespace'] = rtrim($this->namespace.'\\'.studly_case(array_get($attributes, 'namespace', $identifier)), '\\');
75
76 1
            Route::group($attributes, function () use ($identifier) {
77 1
                require base_path('routes/'.$identifier.'.php');
78 1
            });
79
        }
80 1
    }
81
}
82