Completed
Push — master ( 1eda11...6259c1 )
by ARCANEDEV
09:36
created

RouteServiceProvider::getAdminPrefix()   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 0
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
5
/**
6
 * Class     RouteServiceProvider
7
 *
8
 * @package  Arcanesoft\Support\Providers
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
abstract class RouteServiceProvider extends ServiceProvider
12
{
13
    /* ------------------------------------------------------------------------------------------------
14
     |  Main Functions
15
     | ------------------------------------------------------------------------------------------------
16
     */
17
    /**
18
     * Get admin attributes.
19
     *
20
     * @param  string  $name
21
     * @param  string  $namespace
22
     * @param  string  $uri
23
     * @param  array   $middleware
24
     *
25
     * @return array
26
     */
27
    protected function getAdminAttributes($name, $namespace, $uri = '', array $middleware = [])
28
    {
29
        return [
30
            'as'         => $this->prependAdminRouteName($name),
31
            'namespace'  => $namespace,
32
            'prefix'     => $this->prependAdminPrefixUri($uri),
33
            'middleware' => $this->getAdminMiddleware($middleware),
34
        ];
35
    }
36
37
    /**
38
     * Prepend admin route name.
39
     *
40
     * @param  string  $name
41
     *
42
     * @return string
43
     */
44
    protected function prependAdminRouteName($name)
45
    {
46
        return $this->config()->get('arcanesoft.core.admin.route', 'admin::') . $name;
47
    }
48
49
    /**
50
     * Prepend admin uri.
51
     *
52
     * @param  string  $uri
53
     *
54
     * @return string
55
     */
56
    protected function prependAdminPrefixUri($uri = '')
57
    {
58
        $prefix = $this->config()->get('arcanesoft.core.admin.prefix', 'dashboard');
59
60
        return trim("{$prefix}/{$uri}", '/');
61
    }
62
63
    /**
64
     * Get the admin middleware.
65
     *
66
     * @param  array  $append
67
     *
68
     * @return array|mixed
69
     */
70
    protected function getAdminMiddleware(array $append = [])
71
    {
72
        $middleware = $this->config()->get('arcanesoft.core.admin.middleware', []);
73
74
        foreach ($append as $extra) {
75
            if ( ! in_array($extra, $middleware)) $middleware[] = $extra;
76
        }
77
78
        return $middleware;
79
    }
80
81
    /* ------------------------------------------------------------------------------------------------
82
     |  Other Functions
83
     | ------------------------------------------------------------------------------------------------
84
     */
85
    /**
86
     * Get the config repository instance.
87
     *
88
     * @return \Illuminate\Contracts\Config\Repository
89
     */
90
    protected function config()
91
    {
92
        return $this->app['config'];
93
    }
94
}
95