Completed
Push — master ( aba2e5...f36711 )
by ARCANEDEV
12:23
created

registerMiddlewareGroups()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 8
ccs 7
cts 7
cp 1
rs 9.4286
cc 3
eloc 4
nc 3
nop 0
crap 3
1
<?php namespace Arcanedev\Localization\Traits;
2
3
/**
4
 * Class     LocalizationKernelTrait
5
 *
6
 * @package  Arcanedev\Localization\Traits
7
 * @author   ARCANEDEV <[email protected]>
8
 *
9
 * @property  \Illuminate\Foundation\Application      app
10
 * @property  \Arcanedev\Localization\Routing\Router  router
11
 * @property  array                                   middlewareGroups
12
 * @property  array                                   routeMiddleware
13
 */
14
trait LocalizationKernelTrait
15
{
16
    /* ------------------------------------------------------------------------------------------------
17
     |  Main Functions
18
     | ------------------------------------------------------------------------------------------------
19
     */
20
    /**
21
     * Get the route dispatcher callback.
22
     *
23
     * @return \Closure
24
     */
25 60
    protected function dispatchToRouter()
26
    {
27 60
        $this->router = $this->app['router'];
28
29 60
        $this->registerMiddlewareGroups();
30 60
        $this->registerMiddleware();
31
32 60
        return parent::dispatchToRouter();
33
    }
34
35
    /* ------------------------------------------------------------------------------------------------
36
     |  Middleware Functions
37
     | ------------------------------------------------------------------------------------------------
38
     */
39
    /**
40
     * Register middleware groups to router (since Laravel 5.2)
41
     */
42 60
    protected function registerMiddlewareGroups()
43
    {
44 60
        if (property_exists($this, 'middlewareGroups')) {
45 20
            foreach ($this->middlewareGroups as $key => $middleware) {
46 20
                $this->router->middlewareGroup($key, $middleware);
47 15
            }
48 15
        }
49 60
    }
50
51
    /**
52
     * Register middleware to router
53
     */
54 60
    protected function registerMiddleware()
55
    {
56 60
        foreach ($this->routeMiddleware as $key => $middleware) {
57 60
            $this->router->middleware($key, $middleware);
58 45
        }
59 60
    }
60
}
61