@@ -29,11 +29,14 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public function globalMiddleware() |
31 | 31 | { |
32 | - if (isset($this->router->collection->middleware['global_middleware'])) |
|
33 | - foreach ($this->router->collection->middleware['global_middleware'] as $mid) { |
|
32 | + if (isset($this->router->collection->middleware['global_middleware'])) { |
|
33 | + foreach ($this->router->collection->middleware['global_middleware'] as $mid) { |
|
34 | 34 | if (class_exists($mid)) { |
35 | - $mid_global = call_user_func($this->router->getConfig()['di'],$mid); |
|
36 | - if (method_exists($mid_global, 'handle')) $this->callHandler($mid_global); |
|
35 | + $mid_global = call_user_func($this->router->getConfig()['di'],$mid); |
|
36 | + } |
|
37 | + if (method_exists($mid_global, 'handle')) { |
|
38 | + $this->callHandler($mid_global); |
|
39 | + } |
|
37 | 40 | } |
38 | 41 | } |
39 | 42 | } |
@@ -43,11 +46,14 @@ discard block |
||
43 | 46 | */ |
44 | 47 | public function blockMiddleware() |
45 | 48 | { |
46 | - if (isset($this->router->collection->middleware['block_middleware'])) |
|
47 | - if (isset($this->router->collection->middleware['block_middleware'][$this->router->route->getBlock()]) && class_exists($this->router->collection->middleware['block_middleware'][$this->router->route->getBlock()])) { |
|
48 | - $class = $this->router->collection->middleware['block_middleware'][$this->router->route->getBlock()]; |
|
49 | + if (isset($this->router->collection->middleware['block_middleware'])) { |
|
50 | + if (isset($this->router->collection->middleware['block_middleware'][$this->router->route->getBlock()]) && class_exists($this->router->collection->middleware['block_middleware'][$this->router->route->getBlock()])) { |
|
51 | + $class = $this->router->collection->middleware['block_middleware'][$this->router->route->getBlock()]; |
|
52 | + } |
|
49 | 53 | $mid_block = call_user_func($this->router->getConfig()['di'],$class); |
50 | - if (method_exists($mid_block, 'handle')) $this->callHandler($mid_block); |
|
54 | + if (method_exists($mid_block, 'handle')) { |
|
55 | + $this->callHandler($mid_block); |
|
56 | + } |
|
51 | 57 | } |
52 | 58 | } |
53 | 59 | |
@@ -61,7 +67,9 @@ discard block |
||
61 | 67 | if (isset($this->router->collection->middleware['class_middleware'][$ctrl]) && class_exists($this->router->route->getTarget('controller'))) { |
62 | 68 | $class = $this->router->collection->middleware['class_middleware'][$ctrl]; |
63 | 69 | $mid_class = call_user_func($this->router->getConfig()['di'],$class); |
64 | - if (method_exists($mid_class, 'handle')) $this->callHandler($mid_class); |
|
70 | + if (method_exists($mid_class, 'handle')) { |
|
71 | + $this->callHandler($mid_class); |
|
72 | + } |
|
65 | 73 | } |
66 | 74 | } |
67 | 75 | } |
@@ -71,11 +79,14 @@ discard block |
||
71 | 79 | */ |
72 | 80 | public function routeMiddleware() |
73 | 81 | { |
74 | - if (isset($this->router->collection->middleware['route_middleware'])) |
|
75 | - if (isset($this->router->route->getPath()['middleware']) && class_exists($this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']])) { |
|
76 | - $class = $this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']]; |
|
82 | + if (isset($this->router->collection->middleware['route_middleware'])) { |
|
83 | + if (isset($this->router->route->getPath()['middleware']) && class_exists($this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']])) { |
|
84 | + $class = $this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']]; |
|
85 | + } |
|
77 | 86 | $mid_route = call_user_func($this->router->getConfig()['di'],$class); |
78 | - if (method_exists($mid_route, 'handle')) $this->callHandler($mid_route); |
|
87 | + if (method_exists($mid_route, 'handle')) { |
|
88 | + $this->callHandler($mid_route); |
|
89 | + } |
|
79 | 90 | } |
80 | 91 | } |
81 | 92 | |
@@ -86,9 +97,10 @@ discard block |
||
86 | 97 | private function callHandler($instance){ |
87 | 98 | $reflectionMethod = new ReflectionMethod($instance, 'handle'); |
88 | 99 | $dependencies = []; |
89 | - foreach ($reflectionMethod->getParameters() as $arg) |
|
90 | - if (!is_null($arg->getClass())) |
|
91 | - $dependencies[] = $this->getClass($arg->getClass()->name); |
|
100 | + foreach ($reflectionMethod->getParameters() as $arg) { |
|
101 | + if (!is_null($arg->getClass())) |
|
102 | + $dependencies[] = $this->getClass($arg->getClass()->name); |
|
103 | + } |
|
92 | 104 | $dependencies = array_merge($dependencies,[$this->router->route]); |
93 | 105 | return $reflectionMethod->invokeArgs($instance, $dependencies); |
94 | 106 | } |