@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | /** |
26 | 26 | * @var array |
27 | 27 | */ |
28 | - private $resolver = ['isClosureAndTemplate','isControllerAndTemplate','isTemplate']; |
|
28 | + private $resolver = ['isClosureAndTemplate', 'isControllerAndTemplate', 'isTemplate']; |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * @var array |
@@ -47,14 +47,14 @@ discard block |
||
47 | 47 | /** |
48 | 48 | * @param array $resolver |
49 | 49 | */ |
50 | - public function setResolver($resolver = []){ |
|
50 | + public function setResolver($resolver = []) { |
|
51 | 51 | $this->resolver = $resolver; |
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
55 | 55 | * @param string $resolver |
56 | 56 | */ |
57 | - public function addResolver($resolver){ |
|
57 | + public function addResolver($resolver) { |
|
58 | 58 | $this->resolver[] = $resolver; |
59 | 59 | } |
60 | 60 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | /** |
70 | 70 | * @param array $dispatcher |
71 | 71 | */ |
72 | - public function setDispatcher($dispatcher = []){ |
|
72 | + public function setDispatcher($dispatcher = []) { |
|
73 | 73 | $this->dispatcher = $dispatcher; |
74 | 74 | } |
75 | 75 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @return mixed|void |
80 | 80 | * @internal param array $dispatcher |
81 | 81 | */ |
82 | - public function addDispatcher($method,$class){ |
|
82 | + public function addDispatcher($method, $class) { |
|
83 | 83 | $this->dispatcher[$method] = $class; |
84 | 84 | } |
85 | 85 | |
@@ -140,9 +140,9 @@ discard block |
||
140 | 140 | */ |
141 | 141 | private function generateTarget() |
142 | 142 | { |
143 | - if($this->validMethod()) |
|
144 | - foreach($this->resolver as $resolver) |
|
145 | - if (is_array($target = call_user_func_array([$this,$resolver],[$this->router->route->getCallback()]))) { |
|
143 | + if ($this->validMethod()) |
|
144 | + foreach ($this->resolver as $resolver) |
|
145 | + if (is_array($target = call_user_func_array([$this, $resolver], [$this->router->route->getCallback()]))) { |
|
146 | 146 | $this->setTarget($target); |
147 | 147 | $this->router->response->setStatusCode(202); |
148 | 148 | return true; |
@@ -154,20 +154,20 @@ discard block |
||
154 | 154 | /** |
155 | 155 | * @param array $target |
156 | 156 | */ |
157 | - public function setTarget($target = []){ |
|
157 | + public function setTarget($target = []) { |
|
158 | 158 | $index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0; |
159 | 159 | $this->router->route->setDetail($this->request); |
160 | 160 | $this->router->route->setTarget($target); |
161 | - $this->router->route->addTarget('block', $this->router->collection->getRoutes('block_'.$index)); |
|
162 | - $this->router->route->addTarget('view_dir', $this->router->collection->getRoutes('view_dir_'.$index)); |
|
161 | + $this->router->route->addTarget('block', $this->router->collection->getRoutes('block_' . $index)); |
|
162 | + $this->router->route->addTarget('view_dir', $this->router->collection->getRoutes('view_dir_' . $index)); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
166 | 166 | * |
167 | 167 | */ |
168 | - private function setCallback(){ |
|
168 | + private function setCallback() { |
|
169 | 169 | if (isset($this->request['params'])) { |
170 | - if(is_callable($this->request['params'])) |
|
170 | + if (is_callable($this->request['params'])) |
|
171 | 171 | $this->router->route->setCallback($this->request['params']); |
172 | 172 | else { |
173 | 173 | (is_array($this->request['params']) && isset($this->request['params']['use'])) |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | */ |
185 | 185 | public function validMethod() |
186 | 186 | { |
187 | - if(is_callable($this->request['params']))return true; |
|
187 | + if (is_callable($this->request['params']))return true; |
|
188 | 188 | if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') |
189 | 189 | return (isset($this->request['params']['ajax']) && $this->request['params']['ajax'] === true) ? true : false; |
190 | 190 | $method = (isset($this->request['params']['method'])) ? $this->request['params']['method'] : ['GET']; |
@@ -196,10 +196,10 @@ discard block |
||
196 | 196 | * @return array|bool |
197 | 197 | * @throws \Exception |
198 | 198 | */ |
199 | - public function isClosureAndTemplate($callback){ |
|
200 | - if(is_array($cls = $this->isClosure($callback))) { |
|
199 | + public function isClosureAndTemplate($callback) { |
|
200 | + if (is_array($cls = $this->isClosure($callback))) { |
|
201 | 201 | if (is_array($this->request['params']) && isset($this->request['params']['template']) && is_array($tpl = $this->isTemplate($this->request['params']['template']))) { |
202 | - return array_merge(array_merge($cls, $tpl),[ |
|
202 | + return array_merge(array_merge($cls, $tpl), [ |
|
203 | 203 | 'dispatcher' => [$this->dispatcher['matchClosure'], $this->dispatcher['matchTemplate']] |
204 | 204 | ]); |
205 | 205 | } |
@@ -213,10 +213,10 @@ discard block |
||
213 | 213 | * @return array|bool |
214 | 214 | * @throws \Exception |
215 | 215 | */ |
216 | - public function isControllerAndTemplate($callback){ |
|
217 | - if(is_array($ctrl = $this->isController($callback))) { |
|
216 | + public function isControllerAndTemplate($callback) { |
|
217 | + if (is_array($ctrl = $this->isController($callback))) { |
|
218 | 218 | if (is_array($this->request['params']) && isset($this->request['params']['template']) && is_array($tpl = $this->isTemplate($this->request['params']['template']))) { |
219 | - return array_merge(array_merge($ctrl, $tpl),[ |
|
219 | + return array_merge(array_merge($ctrl, $tpl), [ |
|
220 | 220 | 'dispatcher' => [$this->dispatcher['matchController'], $this->dispatcher['matchTemplate']] |
221 | 221 | ]); |
222 | 222 | } |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | $index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0; |
255 | 255 | $class = (class_exists($routes[0])) |
256 | 256 | ? $routes[0] |
257 | - : $this->router->collection->getRoutes()['ctrl_namespace_'.$index].$routes[0]; |
|
257 | + : $this->router->collection->getRoutes()['ctrl_namespace_' . $index] . $routes[0]; |
|
258 | 258 | if (!class_exists($class)) |
259 | 259 | throw new \Exception('Class "' . $class . '." is not found'); |
260 | 260 | if (method_exists($class, $routes[1])) { |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | */ |
278 | 278 | public function isTemplate($callback) |
279 | 279 | { |
280 | - if(is_string($callback)) { |
|
280 | + if (is_string($callback)) { |
|
281 | 281 | $path = trim($callback, '/'); |
282 | 282 | $extension = substr(strrchr($path, "."), 1); |
283 | 283 | $index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0; |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | } |
295 | 295 | } |
296 | 296 | } |
297 | - if(is_null($target)) |
|
297 | + if (is_null($target)) |
|
298 | 298 | throw new \Exception('Template file "' . $path . '" is not found in "' . $viewDir . '"'); |
299 | 299 | return [ |
300 | 300 | 'dispatcher' => $this->dispatcher['matchTemplate'], |
@@ -125,8 +125,9 @@ discard block |
||
125 | 125 | { |
126 | 126 | if (substr($this->request['route'], -1) == '*') { |
127 | 127 | $pos = strpos($this->request['route'], '*'); |
128 | - if (substr($this->router->route->getUrl(), 0, $pos) == substr($this->request['route'], 0, $pos) && isset($this->request['params'])) |
|
129 | - return true; |
|
128 | + if (substr($this->router->route->getUrl(), 0, $pos) == substr($this->request['route'], 0, $pos) && isset($this->request['params'])) { |
|
129 | + return true; |
|
130 | + } |
|
130 | 131 | } |
131 | 132 | if (preg_match($regex, $this->router->route->getUrl(), $this->request['parameters'])) { |
132 | 133 | array_shift($this->request['parameters']); |
@@ -140,10 +141,11 @@ discard block |
||
140 | 141 | */ |
141 | 142 | private function generateTarget() |
142 | 143 | { |
143 | - if($this->validMethod()) |
|
144 | - foreach($this->resolver as $resolver) |
|
144 | + if($this->validMethod()) { |
|
145 | + foreach($this->resolver as $resolver) |
|
145 | 146 | if (is_array($target = call_user_func_array([$this,$resolver],[$this->router->route->getCallback()]))) { |
146 | - $this->setTarget($target); |
|
147 | + $this->setTarget($target); |
|
148 | + } |
|
147 | 149 | $this->router->response->setStatusCode(202); |
148 | 150 | return true; |
149 | 151 | } |
@@ -167,14 +169,18 @@ discard block |
||
167 | 169 | */ |
168 | 170 | private function setCallback(){ |
169 | 171 | if (isset($this->request['params'])) { |
170 | - if(is_callable($this->request['params'])) |
|
171 | - $this->router->route->setCallback($this->request['params']); |
|
172 | - else { |
|
172 | + if(is_callable($this->request['params'])) { |
|
173 | + $this->router->route->setCallback($this->request['params']); |
|
174 | + } else { |
|
173 | 175 | (is_array($this->request['params']) && isset($this->request['params']['use'])) |
174 | 176 | ? $this->router->route->setCallback($this->request['params']['use']) |
175 | 177 | : $this->router->route->setCallback($this->request['params']); |
176 | - if (isset($this->request['params']['name'])) $this->router->route->setName($this->request['params']['name']); |
|
177 | - if (isset($this->request['params']['method'])) $this->request['params']['method'] = is_array($this->request['params']['method']) ? $this->request['params']['method'] : [$this->request['params']['method']]; |
|
178 | + if (isset($this->request['params']['name'])) { |
|
179 | + $this->router->route->setName($this->request['params']['name']); |
|
180 | + } |
|
181 | + if (isset($this->request['params']['method'])) { |
|
182 | + $this->request['params']['method'] = is_array($this->request['params']['method']) ? $this->request['params']['method'] : [$this->request['params']['method']]; |
|
183 | + } |
|
178 | 184 | } |
179 | 185 | } |
180 | 186 | } |
@@ -184,9 +190,12 @@ discard block |
||
184 | 190 | */ |
185 | 191 | public function validMethod() |
186 | 192 | { |
187 | - if(is_callable($this->request['params']))return true; |
|
188 | - if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') |
|
189 | - return (isset($this->request['params']['ajax']) && $this->request['params']['ajax'] === true) ? true : false; |
|
193 | + if(is_callable($this->request['params'])) { |
|
194 | + return true; |
|
195 | + } |
|
196 | + if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { |
|
197 | + return (isset($this->request['params']['ajax']) && $this->request['params']['ajax'] === true) ? true : false; |
|
198 | + } |
|
190 | 199 | $method = (isset($this->request['params']['method'])) ? $this->request['params']['method'] : ['GET']; |
191 | 200 | return (in_array($this->router->route->getMethod(), $method)) ? true : false; |
192 | 201 | } |
@@ -250,13 +259,16 @@ discard block |
||
250 | 259 | { |
251 | 260 | if (is_string($callback) && strpos($callback, '@') !== false) { |
252 | 261 | $routes = explode('@', $callback); |
253 | - if (!isset($routes[1])) $routes[1] = 'index'; |
|
262 | + if (!isset($routes[1])) { |
|
263 | + $routes[1] = 'index'; |
|
264 | + } |
|
254 | 265 | $index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0; |
255 | 266 | $class = (class_exists($routes[0])) |
256 | 267 | ? $routes[0] |
257 | 268 | : $this->router->collection->getRoutes()['ctrl_namespace_'.$index].$routes[0]; |
258 | - if (!class_exists($class)) |
|
259 | - throw new \Exception('Class "' . $class . '." is not found'); |
|
269 | + if (!class_exists($class)) { |
|
270 | + throw new \Exception('Class "' . $class . '." is not found'); |
|
271 | + } |
|
260 | 272 | if (method_exists($class, $routes[1])) { |
261 | 273 | return [ |
262 | 274 | 'dispatcher' => $this->dispatcher['matchController'], |
@@ -283,9 +295,9 @@ discard block |
||
283 | 295 | $index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0; |
284 | 296 | $viewDir = $this->router->collection->getRoutes('view_dir_' . $index); |
285 | 297 | $target = null; |
286 | - if (in_array('.' . $extension, $this->router->getConfig()['templateExtension']) && (is_file($fullPath = $viewDir . $path) || is_file($fullPath = $path))) |
|
287 | - $target = $fullPath; |
|
288 | - else { |
|
298 | + if (in_array('.' . $extension, $this->router->getConfig()['templateExtension']) && (is_file($fullPath = $viewDir . $path) || is_file($fullPath = $path))) { |
|
299 | + $target = $fullPath; |
|
300 | + } else { |
|
289 | 301 | foreach ($this->router->getConfig()['templateExtension'] as $ext) { |
290 | 302 | if (is_file($fullPath = $viewDir . $path . $ext) || is_file($fullPath = $path . $ext)) { |
291 | 303 | $target = $fullPath; |
@@ -294,8 +306,9 @@ discard block |
||
294 | 306 | } |
295 | 307 | } |
296 | 308 | } |
297 | - if(is_null($target)) |
|
298 | - throw new \Exception('Template file "' . $path . '" is not found in "' . $viewDir . '"'); |
|
309 | + if(is_null($target)) { |
|
310 | + throw new \Exception('Template file "' . $path . '" is not found in "' . $viewDir . '"'); |
|
311 | + } |
|
299 | 312 | return [ |
300 | 313 | 'dispatcher' => $this->dispatcher['matchTemplate'], |
301 | 314 | 'template' => $target, |
@@ -45,14 +45,14 @@ discard block |
||
45 | 45 | /** |
46 | 46 | * @param array $resolver |
47 | 47 | */ |
48 | - public function setResolver($resolver = []){ |
|
48 | + public function setResolver($resolver = []) { |
|
49 | 49 | $this->resolver = $resolver; |
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | 53 | * @param string $resolver |
54 | 54 | */ |
55 | - public function addResolver($resolver){ |
|
55 | + public function addResolver($resolver) { |
|
56 | 56 | $this->resolver[] = $resolver; |
57 | 57 | } |
58 | 58 | |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @param $class |
78 | 78 | * @return mixed|void |
79 | 79 | */ |
80 | - public function addDispatcher($method,$class){ |
|
80 | + public function addDispatcher($method, $class) { |
|
81 | 81 | $this->dispatcher[$method] = $class; |
82 | 82 | } |
83 | 83 | |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function match() |
88 | 88 | { |
89 | - foreach($this->resolver as $resolver){ |
|
90 | - if(is_array($target = call_user_func([$this,$resolver]))) { |
|
89 | + foreach ($this->resolver as $resolver) { |
|
90 | + if (is_array($target = call_user_func([$this, $resolver]))) { |
|
91 | 91 | $this->setTarget($target); |
92 | 92 | $this->router->response->setStatusCode(202); |
93 | 93 | return true; |
@@ -99,21 +99,21 @@ discard block |
||
99 | 99 | /** |
100 | 100 | * @param array $target |
101 | 101 | */ |
102 | - public function setTarget($target = []){ |
|
102 | + public function setTarget($target = []) { |
|
103 | 103 | $index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0; |
104 | 104 | $this->router->route->setDetail($this->request); |
105 | 105 | $this->router->route->setTarget($target); |
106 | - $this->router->route->addTarget('block', $this->router->collection->getRoutes('block_'.$index)); |
|
107 | - $this->router->route->addTarget('view_dir', $this->router->collection->getRoutes('view_dir_'.$index)); |
|
106 | + $this->router->route->addTarget('block', $this->router->collection->getRoutes('block_' . $index)); |
|
107 | + $this->router->route->addTarget('view_dir', $this->router->collection->getRoutes('view_dir_' . $index)); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
111 | 111 | * @return array|bool |
112 | 112 | */ |
113 | - public function isControllerAndTemplate(){ |
|
114 | - if(is_array($ctrl = $this->isController())) { |
|
113 | + public function isControllerAndTemplate() { |
|
114 | + if (is_array($ctrl = $this->isController())) { |
|
115 | 115 | if (is_array($tpl = $this->isTemplate())) { |
116 | - return array_merge(array_merge($ctrl, $tpl),[ |
|
116 | + return array_merge(array_merge($ctrl, $tpl), [ |
|
117 | 117 | 'dispatcher' => [$this->dispatcher['matchController'], $this->dispatcher['matchTemplate']] |
118 | 118 | ]); |
119 | 119 | } |
@@ -129,9 +129,9 @@ discard block |
||
129 | 129 | { |
130 | 130 | foreach ($this->router->getConfig()['templateExtension'] as $extension) { |
131 | 131 | for ($i = 0; $i < $this->router->collection->countRoutes; ++$i) { |
132 | - $url = explode('/', str_replace($this->router->collection->getRoutes('prefix_' . $i), '',$this->router->route->getUrl())); |
|
132 | + $url = explode('/', str_replace($this->router->collection->getRoutes('prefix_' . $i), '', $this->router->route->getUrl())); |
|
133 | 133 | $end = array_pop($url); |
134 | - $url = implode('/', array_map('ucwords', $url)).'/'.$end; |
|
134 | + $url = implode('/', array_map('ucwords', $url)) . '/' . $end; |
|
135 | 135 | if (is_file(($template = rtrim($this->router->collection->getRoutes('view_dir_' . $i), '/') . $url . $extension))) { |
136 | 136 | $this->request['collection_index'] = $i; |
137 | 137 | return [ |
@@ -153,13 +153,13 @@ discard block |
||
153 | 153 | { |
154 | 154 | $routes = array_slice(explode('/', $this->router->route->getUrl()), 1); |
155 | 155 | $i = 0; |
156 | - do{ |
|
157 | - $route = ('/' . $routes[0] == $this->router->collection->getRoutes('prefix_' . $i)) ? array_slice($routes, 1) : $routes; |
|
156 | + do { |
|
157 | + $route = ('/' . $routes[0] == $this->router->collection->getRoutes('prefix_' . $i)) ? array_slice($routes, 1) : $routes; |
|
158 | 158 | if (isset($route[0])) { |
159 | - $class = (class_exists($this->router->collection->getRoutes('ctrl_namespace_' . $i). ucfirst($route[0]) . 'Controller')) |
|
160 | - ? $this->router->collection->getRoutes('ctrl_namespace_' . $i). ucfirst($route[0]) . 'Controller' |
|
159 | + $class = (class_exists($this->router->collection->getRoutes('ctrl_namespace_' . $i) . ucfirst($route[0]) . 'Controller')) |
|
160 | + ? $this->router->collection->getRoutes('ctrl_namespace_' . $i) . ucfirst($route[0]) . 'Controller' |
|
161 | 161 | : ucfirst($route[0]) . 'Controller'; |
162 | - $route[1] = isset($route[1])?$route[1]:'index'; |
|
162 | + $route[1] = isset($route[1]) ? $route[1] : 'index'; |
|
163 | 163 | if (method_exists($class, $route[1])) { |
164 | 164 | $this->request['parameters'] = array_slice($route, 2); |
165 | 165 | $this->request['collection_index'] = $i; |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | } |
173 | 173 | } |
174 | 174 | ++$i; |
175 | - }while($i < $this->router->collection->countRoutes); |
|
175 | + }while ($i < $this->router->collection->countRoutes); |
|
176 | 176 | return false; |
177 | 177 | } |
178 | 178 |
@@ -48,13 +48,13 @@ discard block |
||
48 | 48 | * @param ResponseInterface $response |
49 | 49 | * @param Route $route |
50 | 50 | */ |
51 | - public function __construct(RouteCollection $collection,ResponseInterface $response = null,Route $route = null) |
|
51 | + public function __construct(RouteCollection $collection, ResponseInterface $response = null, Route $route = null) |
|
52 | 52 | { |
53 | 53 | $this->collection = $collection; |
54 | - $this->response = is_null($response)? new Response() : $response; |
|
54 | + $this->response = is_null($response) ? new Response() : $response; |
|
55 | 55 | $this->response->setStatusCode(404); |
56 | - $this->route = is_null($route)? new Route() : $route; |
|
57 | - $this->config['di'] = function($class){ |
|
56 | + $this->route = is_null($route) ? new Route() : $route; |
|
57 | + $this->config['di'] = function($class) { |
|
58 | 58 | return new $class; |
59 | 59 | }; |
60 | 60 | } |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | /** |
79 | 79 | * @param object|array $matcher |
80 | 80 | */ |
81 | - public function setMatcher($matcher){ |
|
82 | - if(is_object($matcher)) |
|
81 | + public function setMatcher($matcher) { |
|
82 | + if (is_object($matcher)) |
|
83 | 83 | $matcher = [$matcher]; |
84 | 84 | $this->matcher = $matcher; |
85 | 85 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | /** |
88 | 88 | * @param string $matcher |
89 | 89 | */ |
90 | - public function addMatcher($matcher){ |
|
90 | + public function addMatcher($matcher) { |
|
91 | 91 | $this->matcher[] = $matcher; |
92 | 92 | } |
93 | 93 | |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public function callTarget() |
134 | 134 | { |
135 | - $target = is_array($this->route->getTarget('dispatcher'))?$this->route->getTarget('dispatcher'):[$this->route->getTarget('dispatcher')]; |
|
136 | - if(!empty($target)) { |
|
137 | - foreach($target as $call) { |
|
135 | + $target = is_array($this->route->getTarget('dispatcher')) ? $this->route->getTarget('dispatcher') : [$this->route->getTarget('dispatcher')]; |
|
136 | + if (!empty($target)) { |
|
137 | + foreach ($target as $call) { |
|
138 | 138 | $this->dispatcher = new $call($this->route, $this->response); |
139 | 139 | call_user_func([$this->dispatcher, 'call']); |
140 | 140 | } |
@@ -168,10 +168,10 @@ discard block |
||
168 | 168 | { |
169 | 169 | if (isset($this->route->getDetail()['response_templates']) && isset($this->route->getDetail()['response_templates'][$code = $this->response->getStatusCode()])) { |
170 | 170 | $this->route->setCallback($this->route->getDetail()['response_templates'][$code]); |
171 | - foreach($this->matcher as $key => $instance) { |
|
171 | + foreach ($this->matcher as $key => $instance) { |
|
172 | 172 | foreach (call_user_func([$instance, 'getResolver']) as $match) |
173 | - if (is_array($target = call_user_func_array([$instance, $match], [$this->route->getCallback()]))){ |
|
174 | - call_user_func_array([$instance, 'setTarget'],[$target]); |
|
173 | + if (is_array($target = call_user_func_array([$instance, $match], [$this->route->getCallback()]))) { |
|
174 | + call_user_func_array([$instance, 'setTarget'], [$target]); |
|
175 | 175 | $this->callTarget(); |
176 | 176 | break; |
177 | 177 | } |
@@ -79,8 +79,9 @@ discard block |
||
79 | 79 | * @param object|array $matcher |
80 | 80 | */ |
81 | 81 | public function setMatcher($matcher){ |
82 | - if(is_object($matcher)) |
|
83 | - $matcher = [$matcher]; |
|
82 | + if(is_object($matcher)) { |
|
83 | + $matcher = [$matcher]; |
|
84 | + } |
|
84 | 85 | $this->matcher = $matcher; |
85 | 86 | } |
86 | 87 | |
@@ -97,7 +98,9 @@ discard block |
||
97 | 98 | public function run() |
98 | 99 | { |
99 | 100 | $this->setUrl(); |
100 | - if ($this->config['generateRoutesPath']) $this->collection->generateRoutesPath(); |
|
101 | + if ($this->config['generateRoutesPath']) { |
|
102 | + $this->collection->generateRoutesPath(); |
|
103 | + } |
|
101 | 104 | if ($this->match()) { |
102 | 105 | $this->handle(); |
103 | 106 | $this->callTarget(); |
@@ -110,8 +113,9 @@ discard block |
||
110 | 113 | */ |
111 | 114 | public function setUrl($url = null) |
112 | 115 | { |
113 | - if (is_null($url)) |
|
114 | - $url = (isset($_GET['url'])) ? $_GET['url'] : substr(str_replace(str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']), '', $_SERVER['REQUEST_URI']), 1); |
|
116 | + if (is_null($url)) { |
|
117 | + $url = (isset($_GET['url'])) ? $_GET['url'] : substr(str_replace(str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']), '', $_SERVER['REQUEST_URI']), 1); |
|
118 | + } |
|
115 | 119 | $this->route->setUrl('/' . trim(explode('?', $url)[0], '/')); |
116 | 120 | } |
117 | 121 | |
@@ -121,8 +125,9 @@ discard block |
||
121 | 125 | public function match() |
122 | 126 | { |
123 | 127 | foreach ($this->matcher as $key => $matcher) { |
124 | - if (call_user_func([$this->matcher[$key], 'match'])) |
|
125 | - return true; |
|
128 | + if (call_user_func([$this->matcher[$key], 'match'])) { |
|
129 | + return true; |
|
130 | + } |
|
126 | 131 | } |
127 | 132 | return false; |
128 | 133 | } |
@@ -169,9 +174,10 @@ discard block |
||
169 | 174 | if (isset($this->route->getDetail()['response_templates']) && isset($this->route->getDetail()['response_templates'][$code = $this->response->getStatusCode()])) { |
170 | 175 | $this->route->setCallback($this->route->getDetail()['response_templates'][$code]); |
171 | 176 | foreach($this->matcher as $key => $instance) { |
172 | - foreach (call_user_func([$instance, 'getResolver']) as $match) |
|
173 | - if (is_array($target = call_user_func_array([$instance, $match], [$this->route->getCallback()]))){ |
|
174 | - call_user_func_array([$instance, 'setTarget'],[$target]); |
|
177 | + foreach (call_user_func([$instance, 'getResolver']) as $match) { |
|
178 | + if (is_array($target = call_user_func_array([$instance, $match], [$this->route->getCallback()]))){ |
|
179 | + call_user_func_array([$instance, 'setTarget'],[$target]); |
|
180 | + } |
|
175 | 181 | $this->callTarget(); |
176 | 182 | break; |
177 | 183 | } |