Completed
Pull Request — master (#5)
by ARCANEDEV
06:32
created

RouteServiceProvider::map()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php namespace Arcanesoft\Auth\Providers;
2
3
use Arcanesoft\Auth\Http\Routes;
4
use Arcanesoft\Core\Bases\RouteServiceProvider as ServiceProvider;
5
use Illuminate\Contracts\Routing\Registrar as Router;
6
use Illuminate\Support\Arr;
7
8
/**
9
 * Class     RouteServiceProvider
10
 *
11
 * @package  Arcanesoft\Auth\Providers
12
 * @author   ARCANEDEV <[email protected]>
13
 */
14
class RouteServiceProvider extends ServiceProvider
15
{
16
    /* ------------------------------------------------------------------------------------------------
17
     |  Getters & Setters
18
     | ------------------------------------------------------------------------------------------------
19
     */
20
    /**
21
     * Get the routes namespace
22
     *
23
     * @return string
24
     */
25
    protected function getRouteNamespace()
26
    {
27
        return 'Arcanesoft\\Auth\\Http\\Routes';
28
    }
29
30
    /**
31
     * Get the auth foundation route prefix.
32
     *
33
     * @return string
34
     */
35 24
    public function getFoundationAuthPrefix()
36
    {
37 24
        $prefix = array_get($this->getFoundationRouteGroup(), 'prefix', 'dashboard');
38
39 24
        return "$prefix/" . config('arcanesoft.auth.route.prefix', 'authorization');
40
    }
41
42
    /* ------------------------------------------------------------------------------------------------
43
     |  Main Functions
44
     | ------------------------------------------------------------------------------------------------
45
     */
46
    /**
47
     * Define the routes for the application.
48
     *
49
     * @param  \Illuminate\Contracts\Routing\Registrar  $router
50
     */
51 24
    public function map(Router $router)
52
    {
53 24
        $this->mapPublicRoutes($router);
54 24
        $this->mapFoundationRoutes($router);
55 24
    }
56
57
    /**
58
     * Define the public routes for the application.
59
     *
60
     * @param  \Illuminate\Contracts\Routing\Registrar  $router
61
     */
62 24
    private function mapPublicRoutes(Router $router)
63
    {
64 24
        $configs = $this->config()->get('arcanesoft.auth.authentication.public-routes');
65
66 24
        if ( ! Arr::get($configs, 'enabled', false)) return;
67
68 24
        $attributes = Arr::get($configs, 'attributes', [
69 24
            'prefix'    => 'auth',
70 18
            'as'        => 'auth::',
71 18
            'namespace' => 'Arcanesoft\\Auth\\Http\\Controllers\\Front',
72 18
        ]);
73
74
        $router->group($attributes, function (Router $router) {
75 24
            Routes\Front\AuthenticateRoutes::register($router);
76 24
            Routes\Front\RegisterRoutes::register($router);
77 24
            Routes\Front\ReminderRoutes::register($router);
78 24
        });
79
80 24
        $router->group(array_merge($attributes, [
81 24
            'prefix' => 'api',
82 24
            'as'     => $attributes['as'] . 'api.',
83
        ]), function (Router $router) {
84 24
            Routes\Front\ApiRoutes::register($router);
85 24
        });
86 24
    }
87
88
    /**
89
     * Define the foundation routes for the application.
90
     *
91
     * @param  \Illuminate\Contracts\Routing\Registrar  $router
92
     */
93 24
    private function mapFoundationRoutes(Router $router)
94
    {
95 24
        $attributes = array_merge($this->getFoundationRouteGroup(), [
96 24
            'as'        => 'auth::foundation.',
97 18
            'namespace' => 'Arcanesoft\\Auth\\Http\\Controllers\\Foundation',
98 18
        ]);
99
100
        $router->group($attributes, function (Router $router) {
101 24
            Routes\Foundation\ProfileRoutes::register($router);
102 24
        });
103
104 24
        $router->group(array_merge(
105 18
            $attributes,
106 24
            ['prefix' => $this->getFoundationAuthPrefix()]
107
        ), function (Router $router) {
108 24
            Routes\Foundation\StatsRoutes::register($router);
109 24
            Routes\Foundation\UsersRoutes::register($router);
110 24
            Routes\Foundation\RolesRoutes::register($router);
111 24
            Routes\Foundation\PermissionsRoutes::register($router);
112 24
        });
113
114 24
        $router->group(array_merge(
115 18
            $attributes,
116 24
            ['prefix' => $this->getFoundationAuthPrefix()]
117 24
        ), function (Router $router) {
118 24
            Routes\Foundation\ApiRoutes::register($router);
119 24
        });
120 24
    }
121
}
122