@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | * @param $class |
77 | 77 | * @return mixed |
78 | 78 | */ |
79 | - private function callHandler($class){ |
|
80 | - $instance = call_user_func($this->router->getConfig()['di'],$class); |
|
79 | + private function callHandler($class) { |
|
80 | + $instance = call_user_func($this->router->getConfig()['di'], $class); |
|
81 | 81 | if (method_exists($instance, 'handle')) { |
82 | 82 | $reflectionMethod = new ReflectionMethod($instance, 'handle'); |
83 | 83 | $dependencies = []; |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | * @param $class |
94 | 94 | * @return Route|RouteCollection|Router|mixed |
95 | 95 | */ |
96 | - private function getClass($class){ |
|
97 | - switch($class){ |
|
96 | + private function getClass($class) { |
|
97 | + switch ($class) { |
|
98 | 98 | case 'JetFire\Routing\Route': |
99 | 99 | return $this->router->route; |
100 | 100 | break; |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | return $this->router->collection; |
106 | 106 | break; |
107 | 107 | default: |
108 | - return call_user_func_array($this->router->getConfig()['di'],[$class]); |
|
108 | + return call_user_func_array($this->router->getConfig()['di'], [$class]); |
|
109 | 109 | break; |
110 | 110 | } |
111 | 111 | } |
@@ -29,9 +29,10 @@ 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 $class) |
|
34 | - if (class_exists($class)) $this->callHandler($class); |
|
32 | + if (isset($this->router->collection->middleware['global_middleware'])) { |
|
33 | + foreach ($this->router->collection->middleware['global_middleware'] as $class) |
|
34 | + if (class_exists($class)) $this->callHandler($class); |
|
35 | + } |
|
35 | 36 | } |
36 | 37 | |
37 | 38 | /** |
@@ -39,9 +40,10 @@ discard block |
||
39 | 40 | */ |
40 | 41 | public function blockMiddleware() |
41 | 42 | { |
42 | - if (isset($this->router->collection->middleware['block_middleware'])) |
|
43 | - if (isset($this->router->collection->middleware['block_middleware'][$this->router->route->getTarget('block')]) && class_exists($this->router->collection->middleware['block_middleware'][$this->router->route->getTarget('block')])) { |
|
44 | - $class = $this->router->collection->middleware['block_middleware'][$this->router->route->getTarget('block')]; |
|
43 | + if (isset($this->router->collection->middleware['block_middleware'])) { |
|
44 | + if (isset($this->router->collection->middleware['block_middleware'][$this->router->route->getTarget('block')]) && class_exists($this->router->collection->middleware['block_middleware'][$this->router->route->getTarget('block')])) { |
|
45 | + $class = $this->router->collection->middleware['block_middleware'][$this->router->route->getTarget('block')]; |
|
46 | + } |
|
45 | 47 | $this->callHandler($class); |
46 | 48 | } |
47 | 49 | } |
@@ -65,9 +67,10 @@ discard block |
||
65 | 67 | */ |
66 | 68 | public function routeMiddleware() |
67 | 69 | { |
68 | - if (isset($this->router->collection->middleware['route_middleware'])) |
|
69 | - if (isset($this->router->route->getPath()['middleware']) && class_exists($this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']])) { |
|
70 | - $class = $this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']]; |
|
70 | + if (isset($this->router->collection->middleware['route_middleware'])) { |
|
71 | + if (isset($this->router->route->getPath()['middleware']) && class_exists($this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']])) { |
|
72 | + $class = $this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']]; |
|
73 | + } |
|
71 | 74 | $this->callHandler($class); |
72 | 75 | } |
73 | 76 | } |
@@ -81,9 +84,10 @@ discard block |
||
81 | 84 | if (method_exists($instance, 'handle')) { |
82 | 85 | $reflectionMethod = new ReflectionMethod($instance, 'handle'); |
83 | 86 | $dependencies = []; |
84 | - foreach ($reflectionMethod->getParameters() as $arg) |
|
85 | - if (!is_null($arg->getClass())) |
|
86 | - $dependencies[] = $this->getClass($arg->getClass()->name); |
|
87 | + foreach ($reflectionMethod->getParameters() as $arg) { |
|
88 | + if (!is_null($arg->getClass())) |
|
89 | + $dependencies[] = $this->getClass($arg->getClass()->name); |
|
90 | + } |
|
87 | 91 | $dependencies = array_merge($dependencies, [$this->router->route]); |
88 | 92 | $reflectionMethod->invokeArgs($instance, $dependencies); |
89 | 93 | } |