@@ -118,12 +118,12 @@ discard block |
||
| 118 | 118 | $found = false; |
| 119 | 119 | $counter = 0; |
| 120 | 120 | |
| 121 | - if(count($this->routes) === 0) { |
|
| 121 | + if (count($this->routes) === 0) { |
|
| 122 | 122 | return $found; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - while($found === false && $counter < count($this->routes)) { |
|
| 126 | - if($this->routes[$counter]->getUri() === $uri && $this->routes[$counter]->getMethod() === $method) { |
|
| 125 | + while ($found === false && $counter < count($this->routes)) { |
|
| 126 | + if ($this->routes[$counter]->getUri() === $uri && $this->routes[$counter]->getMethod() === $method) { |
|
| 127 | 127 | $found = true; |
| 128 | 128 | } |
| 129 | 129 | |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | */ |
| 144 | 144 | |
| 145 | 145 | private function addRoute($uri, $method, $response, array $middleware = []) { |
| 146 | - if($this->find($uri, $method)) { // search if exists an apparition |
|
| 146 | + if ($this->find($uri, $method)) { // search if exists an apparition |
|
| 147 | 147 | return false; |
| 148 | 148 | } |
| 149 | 149 | |
@@ -159,13 +159,13 @@ discard block |
||
| 159 | 159 | */ |
| 160 | 160 | public function getRequestHeaders() { |
| 161 | 161 | // If getallheaders() is available, use that |
| 162 | - if(function_exists('getallheaders')) { |
|
| 162 | + if (function_exists('getallheaders')) { |
|
| 163 | 163 | return getallheaders(); |
| 164 | 164 | } |
| 165 | 165 | // Method getallheaders() not available: manually extract 'm |
| 166 | 166 | $headers = []; |
| 167 | - foreach($_SERVER as $key => $value) { |
|
| 168 | - if((substr($key, 0, 5) == 'HTTP_') || ($key == 'CONTENT_TYPE') || ($key == 'CONTENT_LENGTH')) { |
|
| 167 | + foreach ($_SERVER as $key => $value) { |
|
| 168 | + if ((substr($key, 0, 5) == 'HTTP_') || ($key == 'CONTENT_TYPE') || ($key == 'CONTENT_LENGTH')) { |
|
| 169 | 169 | $headers[str_replace([' ', 'Http'], ['-', 'HTTP'], ucwords(strtolower(str_replace('_', ' ', substr($key, 5)))))] = $value; |
| 170 | 170 | } |
| 171 | 171 | } |
@@ -177,13 +177,13 @@ discard block |
||
| 177 | 177 | */ |
| 178 | 178 | |
| 179 | 179 | public function overrideMethod() { |
| 180 | - if($this->requestMethod === 'HEAD') { |
|
| 180 | + if ($this->requestMethod === 'HEAD') { |
|
| 181 | 181 | $this->requestMethod = 'GET'; |
| 182 | - } elseif($this->requestMethod === 'POST' && filter_input(INPUT_POST, '_method') !== null) { |
|
| 182 | + } elseif ($this->requestMethod === 'POST' && filter_input(INPUT_POST, '_method') !== null) { |
|
| 183 | 183 | $this->requestMethod = filter_input(INPUT_POST, '_method'); |
| 184 | - } elseif($this->requestMethod === 'POST') { |
|
| 184 | + } elseif ($this->requestMethod === 'POST') { |
|
| 185 | 185 | $headers = $this->getRequestHeaders(); |
| 186 | - if(isset($headers['X-HTTP-Method-Override']) && in_array($headers['X-HTTP-Method-Override'], ['PUT', 'DELETE', 'PATCH'])) { |
|
| 186 | + if (isset($headers['X-HTTP-Method-Override']) && in_array($headers['X-HTTP-Method-Override'], ['PUT', 'DELETE', 'PATCH'])) { |
|
| 187 | 187 | $this->requestMethod = $headers['X-HTTP-Method-Override']; |
| 188 | 188 | } |
| 189 | 189 | } |
@@ -262,8 +262,8 @@ discard block |
||
| 262 | 262 | */ |
| 263 | 263 | |
| 264 | 264 | public function both($uri, $response, $methods = Method::GET, array $middleware = []) { |
| 265 | - if(is_array($methods)) { |
|
| 266 | - foreach($methods as $method) { |
|
| 265 | + if (is_array($methods)) { |
|
| 266 | + foreach ($methods as $method) { |
|
| 267 | 267 | $this->addRoute($uri, $method, $response, $middleware); |
| 268 | 268 | } |
| 269 | 269 | } else { |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | */ |
| 291 | 291 | |
| 292 | 292 | public function notFound($func) { |
| 293 | - if(is_callable($func)) { |
|
| 293 | + if (is_callable($func)) { |
|
| 294 | 294 | $this->notFound = $func; |
| 295 | 295 | } |
| 296 | 296 | } |
@@ -308,17 +308,17 @@ discard block |
||
| 308 | 308 | public function run() { |
| 309 | 309 | $found = false; |
| 310 | 310 | $counter = 0; |
| 311 | - while($found === false && $counter < count($this->routes)) { |
|
| 312 | - if($this->routerParser->match($this->routes[$counter]->getUri()) && $this->routes[$counter]->getMethod() === $this->requestMethod) { |
|
| 311 | + while ($found === false && $counter < count($this->routes)) { |
|
| 312 | + if ($this->routerParser->match($this->routes[$counter]->getUri()) && $this->routes[$counter]->getMethod() === $this->requestMethod) { |
|
| 313 | 313 | $found = true; |
| 314 | 314 | } else { |
| 315 | 315 | $counter++; |
| 316 | 316 | } |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - if($found) { |
|
| 319 | + if ($found) { |
|
| 320 | 320 | // run the before middleware if it exists |
| 321 | - if($this->routes[$counter]->hasBefore()) { |
|
| 321 | + if ($this->routes[$counter]->hasBefore()) { |
|
| 322 | 322 | call_user_func($this->routes[$counter]->getMiddlewares()['before']); |
| 323 | 323 | } |
| 324 | 324 | |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | $response = call_user_func_array($this->routes[$counter]->getResponse(), $params); |
| 327 | 327 | |
| 328 | 328 | // run the after middleware if it exists |
| 329 | - if($this->routes[$counter]->hasAfter()) { |
|
| 329 | + if ($this->routes[$counter]->hasAfter()) { |
|
| 330 | 330 | call_user_func($this->routes[$counter]->getMiddlewares()['after']); |
| 331 | 331 | } |
| 332 | 332 | |