BackendServiceProvider::loadBackendAuthConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Yeelight\Providers;
4
5
use Illuminate\Support\ServiceProvider;
6
7
/**
8
 * Class BackendServiceProvider
9
 *
10
 * @category Yeelight
11
 *
12
 * @package Yeelight\Providers
13
 *
14
 * @author Sheldon Lee <[email protected]>
15
 *
16
 * @license https://opensource.org/licenses/MIT MIT
17
 *
18
 * @link https://www.yeelight.com
19
 */
20
class BackendServiceProvider extends ServiceProvider
21
{
22
    /**
23
     * The application's route middleware.
24
     *
25
     * @var array
26
     */
27
    protected $routeMiddleware = [
28
        'backend.auth'       => \Yeelight\Http\Middleware\Authenticate::class,
29
        'backend.pjax'       => \Yeelight\Http\Middleware\Pjax::class,
30
        'backend.log'        => \Yeelight\Http\Middleware\LogOperation::class,
31
        'backend.permission' => \Yeelight\Http\Middleware\Permission::class,
32
    ];
33
34
    /**
35
     * The application's route middleware groups.
36
     *
37
     * @var array
38
     */
39
    protected $middlewareGroups = [
40
        'backend' => [
41
            'backend.auth',
42
            'backend.pjax',
43
            'backend.log',
44
        ],
45
    ];
46
47
    /**
48
     * Boot the service provider.
49
     *
50
     * @return void
51
     */
52
    public function boot()
53
    {
54
    }
55
56
    /**
57
     * Register the service provider.
58
     *
59
     * @return void
60
     */
61
    public function register()
62
    {
63
        $this->loadBackendAuthConfig();
64
65
        $this->registerRouteMiddleware();
66
    }
67
68
    /**
69
     * Setup auth configuration.
70
     *
71
     * @return void
72
     */
73
    protected function loadBackendAuthConfig()
74
    {
75
        config(array_dot(config('yeelight.backend.auth', []), 'auth.'));
76
    }
77
78
    /**
79
     * Register the route middleware.
80
     *
81
     * @return void
82
     */
83
    protected function registerRouteMiddleware()
84
    {
85
        // register route middleware.
86
        foreach ($this->routeMiddleware as $key => $middleware) {
87
            app('router')->aliasMiddleware($key, $middleware);
88
        }
89
90
        // register middleware group.
91
        foreach ($this->middlewareGroups as $key => $middleware) {
92
            app('router')->middlewareGroup($key, $middleware);
93
        }
94
    }
95
}
96