Completed
Pull Request — master (#16)
by ARCANEDEV
05:25
created

RouteServiceProvider::mapPublicRoutes()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 28
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 2

Importance

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