Completed
Pull Request — master (#9)
by ARCANEDEV
04:02
created

RouteServiceProvider::mapFoundationRoutes()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 1

Importance

Changes 4
Bugs 0 Features 0
Metric Value
dl 0
loc 28
rs 8.8571
c 4
b 0
f 0
ccs 19
cts 19
cp 1
cc 1
eloc 19
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');
65
        $attributes = Arr::get($configs, 'routes.global', [
66 24
            'prefix'    => 'auth',
67
            'as'        => 'auth::',
68 24
            'namespace' => 'Arcanesoft\\Auth\\Http\\Controllers\\Front',
69 24
        ]);
70 18
71 18
        $router->group($attributes, function (Router $router) {
72 18
            Routes\Front\AuthenticationRoutes::register($router);
73
            Routes\Front\RegisterRoutes::register($router);
74
            Routes\Front\PasswordResetRoutes::register($router);
75 24
        });
76 24
77 24
        $router->group(array_merge($attributes, [
78 24
            'prefix' => 'api',
79
            'as'     => $attributes['as'] . 'api.',
80 24
        ]), function (Router $router) {
81 24
            Routes\Front\ApiRoutes::register($router);
82 24
        });
83
    }
84 24
85 24
    /**
86 24
     * Define the foundation routes for the application.
87
     *
88
     * @param  \Illuminate\Contracts\Routing\Registrar  $router
89
     */
90
    private function mapFoundationRoutes(Router $router)
91
    {
92
        $attributes = array_merge($this->getFoundationRouteGroup(), [
93 24
            'as'        => 'auth::foundation.',
94
            'namespace' => 'Arcanesoft\\Auth\\Http\\Controllers\\Foundation',
95 24
        ]);
96 24
97 18
        $router->group($attributes, function (Router $router) {
98 18
            Routes\Foundation\ProfileRoutes::register($router);
99
        });
100
101 24
        $router->group(array_merge(
102 24
            $attributes,
103
            ['prefix' => $this->getFoundationAuthPrefix()]
104 24
        ), function (Router $router) {
105 18
            Routes\Foundation\StatsRoutes::register($router);
106 24
            Routes\Foundation\UsersRoutes::register($router);
107
            Routes\Foundation\RolesRoutes::register($router);
108 24
            Routes\Foundation\PermissionsRoutes::register($router);
109 24
        });
110 24
111 24
        $router->group(array_merge(
112 24
            $attributes,
113
            ['prefix' => $this->getFoundationAuthPrefix()]
114 24
        ), function (Router $router) {
115 18
            Routes\Foundation\ApiRoutes::register($router);
116 24
        });
117 24
    }
118
}
119