Completed
Push — master ( f3a328...1eda11 )
by ARCANEDEV
03:42
created

RouteServiceProvider::prependAdminRouteName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php namespace Arcanesoft\Core\Bases;
2
3
use Arcanedev\Support\Providers\RouteServiceProvider as ServiceProvider;
4
use Illuminate\Support\Arr;
5
6
/**
7
 * Class     RouteServiceProvider
8
 *
9
 * @package  Arcanesoft\Support\Providers
10
 * @author   ARCANEDEV <[email protected]>
11
 *
12
 * @todo: Remove deprecated functions
13
 */
14
abstract class RouteServiceProvider extends ServiceProvider
15
{
16
    /* ------------------------------------------------------------------------------------------------
17
     |  Main Functions
18
     | ------------------------------------------------------------------------------------------------
19
     */
20
    /**
21
     * Get admin attributes.
22
     *
23
     * @param  string  $name
24
     * @param  string  $namespace
25
     * @param  string  $uri
26
     * @param  array   $middleware
27
     *
28
     * @return array
29
     */
30
    protected function getAdminAttributes($name, $namespace, $uri = '', array $middleware = [])
31
    {
32
        return [
33
            'as'         => $this->prependAdminRouteName($name),
34
            'namespace'  => $namespace,
35
            'prefix'     => $this->prependAdminPrefixUri($uri),
36
            'middleware' => $this->getAdminMiddleware($middleware),
37
        ];
38
    }
39
40
    /**
41
     * Prepend admin route name.
42
     *
43
     * @param  string  $name
44
     *
45
     * @return string
46
     */
47
    protected function prependAdminRouteName($name)
48
    {
49
        return $this->config()->get('arcanesoft.core.admin.route', 'admin::') . $name;
50
    }
51
52
    /**
53
     * Prepend admin uri.
54
     *
55
     * @param  string  $uri
56
     *
57
     * @return string
58
     */
59
    protected function prependAdminPrefixUri($uri = '')
60
    {
61
        $prefix = $this->config()->get('arcanesoft.core.admin.prefix', 'dashboard');
62
63
        return trim("{$prefix}/{$uri}", '/');
64
    }
65
66
    /**
67
     * Get the admin middleware.
68
     *
69
     * @param  array  $append
70
     *
71
     * @return array|mixed
72
     */
73
    protected function getAdminMiddleware(array $append = [])
74
    {
75
        $middleware = $this->config()->get('arcanesoft.core.admin.middleware', []);
76
77
        foreach ($append as $extra) {
78
            if ( ! in_array($extra, $middleware)) $middleware[] = $extra;
79
        }
80
81
        return $middleware;
82
    }
83
84
    /* ------------------------------------------------------------------------------------------------
85
     |  Other Functions
86
     | ------------------------------------------------------------------------------------------------
87
     */
88
    /**
89
     * Get the config repository instance.
90
     *
91
     * @return \Illuminate\Contracts\Config\Repository
92
     */
93
    protected function config()
94
    {
95
        return $this->app['config'];
96
    }
97
98
    /* ------------------------------------------------------------------------------------------------
99
     |  Deprecated Functions
100
     | ------------------------------------------------------------------------------------------------
101
     */
102
    /**
103
     * Get Foundation route group.
104
     *
105
     * @deprecated
106
     *
107
     * @return array
108
     */
109
    protected function getAdminRouteGroup()
110
    {
111
        return $this->config()->get('arcanesoft.foundation.route', []);
112
    }
113
114
    /**
115
     * Get Foundation route prefix.
116
     *
117
     * @deprecated
118
     *
119
     * @return string
120
     */
121
    protected function getAdminPrefix()
122
    {
123
        return Arr::get($this->getAdminRouteGroup(), 'prefix', 'dashboard');
0 ignored issues
show
Deprecated Code introduced by
The method Arcanesoft\Core\Bases\Ro...r::getAdminRouteGroup() has been deprecated.

This method has been deprecated.

Loading history...
124
    }
125
126
    /**
127
     * Get Foundation route group.
128
     *
129
     * @deprecated
130
     *
131
     * @return array
132
     */
133
    protected function getFoundationRouteGroup()
134
    {
135
        return $this->getAdminRouteGroup();
0 ignored issues
show
Deprecated Code introduced by
The method Arcanesoft\Core\Bases\Ro...r::getAdminRouteGroup() has been deprecated.

This method has been deprecated.

Loading history...
136
    }
137
138
    /**
139
     * Get Foundation route prefix.
140
     *
141
     * @deprecated
142
     *
143
     * @return string
144
     */
145
    protected function getFoundationPrefix()
146
    {
147
        return $this->getAdminPrefix();
0 ignored issues
show
Deprecated Code introduced by
The method Arcanesoft\Core\Bases\Ro...vider::getAdminPrefix() has been deprecated.

This method has been deprecated.

Loading history...
148
    }
149
}
150