Completed
Push — master ( 7a04c3...babefc )
by ARCANEDEV
03:27
created

RouteServiceProvider::getAdminMiddleware()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 10
ccs 0
cts 6
cp 0
crap 12
rs 9.4285
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
abstract class RouteServiceProvider extends ServiceProvider
13
{
14
    /* -----------------------------------------------------------------
15
     |  Properties
16
     | -----------------------------------------------------------------
17
     */
18
    /**
19
     * The admin controller namespace for the application.
20
     *
21
     * @var string|null
22
     */
23
    protected $adminNamespace;
24
25
    /* -----------------------------------------------------------------
26
     |  Getters & Setters
27
     | -----------------------------------------------------------------
28
     */
29
    /**
30
     * Get the config repository instance.
31
     *
32
     * @return \Illuminate\Contracts\Config\Repository
33
     */
34
    protected function config()
35
    {
36
        return $this->app->make('config');
37
    }
38
39
    /* -----------------------------------------------------------------
40
     |  Main Methods
41
     | -----------------------------------------------------------------
42
     */
43
    /**
44
     * Group the routes with admin attributes.
45
     *
46
     * @param  \Closure  $callback
47
     */
48
    protected function adminGroup(\Closure $callback)
49
    {
50
        $attributes = $this->config()->get('arcanesoft.core.admin', []);
51
52
        $this->prefix(Arr::get($attributes, 'prefix', 'dashboard'))
53
             ->name(Arr::get($attributes, 'name', 'admin::'))
54
             ->namespace($this->adminNamespace)
55
             ->middleware(Arr::get($attributes, 'middleware', ['web', 'auth', 'admin']))
56
             ->group($callback);
57
    }
58
59
    /* -----------------------------------------------------------------
60
     |  Deprecated Methods
61
     | -----------------------------------------------------------------
62
     */
63
    /**
64
     * Get admin attributes.
65
     *
66
     * @deprecated: Use adminGroup(\Closure $callback) instead
67
     *
68
     * @param  string  $name
69
     * @param  string  $namespace
70
     * @param  string  $uri
71
     * @param  array   $middleware
72
     *
73
     * @return array
74
     */
75
    protected function getAdminAttributes($name, $namespace, $uri = '', array $middleware = [])
76
    {
77
        return [
78
            'as'         => $this->prependAdminRouteName($name),
0 ignored issues
show
Deprecated Code introduced by
The method Arcanesoft\Core\Bases\Ro...prependAdminRouteName() has been deprecated with message: : Use adminGroup(\Closure $callback) instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
79
            'namespace'  => $namespace,
80
            'prefix'     => $this->prependAdminPrefixUri($uri),
0 ignored issues
show
Deprecated Code introduced by
The method Arcanesoft\Core\Bases\Ro...prependAdminPrefixUri() has been deprecated with message: : Use adminGroup(\Closure $callback) instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
81
            'middleware' => $this->getAdminMiddleware($middleware),
0 ignored issues
show
Deprecated Code introduced by
The method Arcanesoft\Core\Bases\Ro...r::getAdminMiddleware() has been deprecated with message: : Use adminGroup(\Closure $callback) instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
82
        ];
83
    }
84
85
    /**
86
     * Prepend admin route name.
87
     *
88
     * @deprecated: Use adminGroup(\Closure $callback) instead
89
     *
90
     * @param  string  $name
91
     *
92
     * @return string
93
     */
94
    protected function prependAdminRouteName($name)
95
    {
96
        return $this->config()->get('arcanesoft.core.admin.route', 'admin::') . $name;
97
    }
98
99
    /**
100
     * Prepend admin uri.
101
     *
102
     * @deprecated: Use adminGroup(\Closure $callback) instead
103
     *
104
     * @param  string  $uri
105
     *
106
     * @return string
107
     */
108
    protected function prependAdminPrefixUri($uri = '')
109
    {
110
        $prefix = $this->config()->get('arcanesoft.core.admin.prefix', 'dashboard');
111
112
        return trim("{$prefix}/{$uri}", '/');
113
    }
114
115
    /**
116
     * Get the admin middleware.
117
     *
118
     * @deprecated: Use adminGroup(\Closure $callback) instead
119
     *
120
     * @param  array  $append
121
     *
122
     * @return array|mixed
123
     */
124
    protected function getAdminMiddleware(array $append = [])
125
    {
126
        $middleware = $this->config()->get('arcanesoft.core.admin.middleware', []);
127
128
        foreach ($append as $extra) {
129
            if ( ! in_array($extra, $middleware)) $middleware[] = $extra;
130
        }
131
132
        return $middleware;
133
    }
134
}
135