Completed
Pull Request — master (#16)
by ARCANEDEV
04:06
created

RouteServiceProvider::mapPublicRoutes()   B

Complexity

Conditions 3
Paths 1

Size

Total Lines 28
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 3

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