@@ -118,7 +118,6 @@ discard block |
||
| 118 | 118 | * Generic method to add a improved route |
| 119 | 119 | * |
| 120 | 120 | * @param mixed $verb String or array of string of valid HTTP Verbs that will be accepted in this route |
| 121 | - * @param mixed $url String or array of strings that will trigger this route |
|
| 122 | 121 | * @param array $attr Associative array of route attributes |
| 123 | 122 | * @param bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside |
| 124 | 123 | * |
@@ -277,7 +276,7 @@ discard block |
||
| 277 | 276 | /** |
| 278 | 277 | * Adds a GET route, alias of Route::add('GET',$url,$attr,$hideOriginal) |
| 279 | 278 | * |
| 280 | - * @param mixed $url String or array of strings that will trigger this route |
|
| 279 | + * @param string $url String or array of strings that will trigger this route |
|
| 281 | 280 | * @param array $attr Associative array of route attributes |
| 282 | 281 | * @param bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside |
| 283 | 282 | * |
@@ -295,7 +294,7 @@ discard block |
||
| 295 | 294 | /** |
| 296 | 295 | * Adds a POST route, alias of Route::add('POST',$url,$attr,$hideOriginal) |
| 297 | 296 | * |
| 298 | - * @param mixed $url String or array of strings that will trigger this route |
|
| 297 | + * @param string $url String or array of strings that will trigger this route |
|
| 299 | 298 | * @param array $attr Associative array of route attributes |
| 300 | 299 | * @param bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside |
| 301 | 300 | * |
@@ -349,7 +348,7 @@ discard block |
||
| 349 | 348 | /** |
| 350 | 349 | * Adds a DELETE route, alias of Route::add('DELETE',$url,$attr,$hideOriginal) |
| 351 | 350 | * |
| 352 | - * @param mixed $url String or array of strings that will trigger this route |
|
| 351 | + * @param string $url String or array of strings that will trigger this route |
|
| 353 | 352 | * @param array $attr Associative array of route attributes |
| 354 | 353 | * @param bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside |
| 355 | 354 | * |
@@ -389,8 +388,8 @@ discard block |
||
| 389 | 388 | /** |
| 390 | 389 | * Adds a list of routes with the verbs contained in $verbs, alias of Route::add($verbs,$url,$attr,$hideOriginal) |
| 391 | 390 | * |
| 392 | - * @param mixed $verb String or array of string of valid HTTP Verbs that will be accepted in this route |
|
| 393 | - * @param mixed $url String or array of strings that will trigger this route |
|
| 391 | + * @param string[] $verbs String or array of string of valid HTTP Verbs that will be accepted in this route |
|
| 392 | + * @param string $url String or array of strings that will trigger this route |
|
| 394 | 393 | * @param array $attr Associative array of route attributes |
| 395 | 394 | * @param bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside |
| 396 | 395 | * |
@@ -800,10 +799,6 @@ discard block |
||
| 800 | 799 | /** |
| 801 | 800 | * Creates the 'default_controller' key in CodeIgniter's route array |
| 802 | 801 | * |
| 803 | - * @param string $route controller/method name |
|
| 804 | - * @param string $alias (Optional) alias of the default controller |
|
| 805 | - * |
|
| 806 | - * Due a CodeIgniter limitations, this route MAY NOT be a directory. |
|
| 807 | 802 | * |
| 808 | 803 | * @return void |
| 809 | 804 | * |
@@ -861,7 +856,7 @@ discard block |
||
| 861 | 856 | /** |
| 862 | 857 | * Get all hidden routes |
| 863 | 858 | * |
| 864 | - * @return array |
|
| 859 | + * @return Route |
|
| 865 | 860 | * |
| 866 | 861 | * @access public |
| 867 | 862 | * @static |
@@ -941,8 +936,9 @@ discard block |
||
| 941 | 936 | * This is the 'reverse' process of the improved routing, it'll take the current |
| 942 | 937 | * uri string and attempts to find a CodeIgniter route that matches with his pattern |
| 943 | 938 | * |
| 944 | - * @param string $search |
|
| 945 | 939 | * |
| 940 | + * @param Middleware $path |
|
| 941 | + * @param string $requestMethod |
|
| 946 | 942 | * @return mixed |
| 947 | 943 | */ |
| 948 | 944 | public static function getRouteByPath($path, $requestMethod = NULL) |
@@ -1067,7 +1063,7 @@ discard block |
||
| 1067 | 1063 | /** |
| 1068 | 1064 | * Returns an array with the valid HTTP Verbs used in routes |
| 1069 | 1065 | * |
| 1070 | - * @return array |
|
| 1066 | + * @return Route |
|
| 1071 | 1067 | * |
| 1072 | 1068 | * @access public |
| 1073 | 1069 | * @static |
@@ -1082,7 +1078,6 @@ discard block |
||
| 1082 | 1078 | * Set the 404 error controller ($route['404_override']) |
| 1083 | 1079 | * |
| 1084 | 1080 | * @param string $controller |
| 1085 | - * @param string $namespace (Optional) |
|
| 1086 | 1081 | * |
| 1087 | 1082 | * @return void |
| 1088 | 1083 | * |
@@ -1102,9 +1097,9 @@ discard block |
||
| 1102 | 1097 | /** |
| 1103 | 1098 | * Get the 404 route |
| 1104 | 1099 | * |
| 1105 | - * @return array $_404page |
|
| 1100 | + * @return Route $_404page |
|
| 1106 | 1101 | * |
| 1107 | - * @return object | null |
|
| 1102 | + * @return Route | null |
|
| 1108 | 1103 | * |
| 1109 | 1104 | * @access public |
| 1110 | 1105 | * @static |
@@ -129,17 +129,17 @@ discard block |
||
| 129 | 129 | */ |
| 130 | 130 | public static function add($verb, $path, $attr, $hideOriginal = TRUE, $return = FALSE) |
| 131 | 131 | { |
| 132 | - if(!is_array($attr)) |
|
| 132 | + if (!is_array($attr)) |
|
| 133 | 133 | { |
| 134 | - show_error('You must specify the route attributes as an array',500,'Route error: bad attributes'); |
|
| 134 | + show_error('You must specify the route attributes as an array', 500, 'Route error: bad attributes'); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - if(!isset($attr['uses'])) |
|
| 137 | + if (!isset($attr['uses'])) |
|
| 138 | 138 | { |
| 139 | 139 | show_error('Route requires a \'controller@method\' to be pointed and it\'s not defined in the route attributes', 500, 'Route error: missing controller'); |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - if(!preg_match('/^([a-zA-Z1-9-_]+)@([a-zA-Z1-9-_]+)$/', $attr['uses'], $parsedController) !== FALSE) |
|
| 142 | + if (!preg_match('/^([a-zA-Z1-9-_]+)@([a-zA-Z1-9-_]+)$/', $attr['uses'], $parsedController) !== FALSE) |
|
| 143 | 143 | { |
| 144 | 144 | show_error('Route controller must be in format controller@method', 500, 'Route error: bad controller format'); |
| 145 | 145 | } |
@@ -147,34 +147,34 @@ discard block |
||
| 147 | 147 | $controller = $parsedController[1]; |
| 148 | 148 | $method = $parsedController[2]; |
| 149 | 149 | |
| 150 | - if(!is_string($path)) |
|
| 150 | + if (!is_string($path)) |
|
| 151 | 151 | show_error('Route path must be a string ', 500, 'Route error: bad route path'); |
| 152 | 152 | |
| 153 | - if(!is_string($verb)) |
|
| 153 | + if (!is_string($verb)) |
|
| 154 | 154 | show_error('Route HTTP Verb must be a string', 500, 'Route error: bad verb type'); |
| 155 | 155 | |
| 156 | 156 | $verb = strtoupper($verb); |
| 157 | 157 | |
| 158 | - if(!in_array($verb, self::$http_verbs,TRUE)) |
|
| 158 | + if (!in_array($verb, self::$http_verbs, TRUE)) |
|
| 159 | 159 | { |
| 160 | 160 | $errorMsg = 'Verb "'.$verb.'" is not a valid HTTP Verb, allowed verbs:<ul>'; |
| 161 | - foreach( self::$http_verbs as $validVerb ) |
|
| 161 | + foreach (self::$http_verbs as $validVerb) |
|
| 162 | 162 | { |
| 163 | 163 | $errorMsg .= '<li>'.$validVerb.'</li>'; |
| 164 | 164 | } |
| 165 | 165 | $errorMsg .= '</ul>'; |
| 166 | - show_error($errorMsg,500,'Route error: unknow method'); |
|
| 166 | + show_error($errorMsg, 500, 'Route error: unknow method'); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | $route['verb'] = $verb; |
| 170 | 170 | |
| 171 | - $path = trim($path,'/'); |
|
| 171 | + $path = trim($path, '/'); |
|
| 172 | 172 | |
| 173 | 173 | $route['path'] = $path; |
| 174 | 174 | $route['controller'] = $controller; |
| 175 | 175 | $route['method'] = $method; |
| 176 | 176 | |
| 177 | - if(isset($attr['as'])) |
|
| 177 | + if (isset($attr['as'])) |
|
| 178 | 178 | { |
| 179 | 179 | $route['name'] = $attr['as']; |
| 180 | 180 | } |
@@ -188,10 +188,10 @@ discard block |
||
| 188 | 188 | $route['prefix'] = NULL; |
| 189 | 189 | $group_prefix = implode('/', self::$prefix); |
| 190 | 190 | |
| 191 | - if($group_prefix) |
|
| 191 | + if ($group_prefix) |
|
| 192 | 192 | $route['prefix'] = $group_prefix.'/'; |
| 193 | 193 | |
| 194 | - if(isset($attr['prefix'])) |
|
| 194 | + if (isset($attr['prefix'])) |
|
| 195 | 195 | $route['prefix'] .= $attr['prefix']; |
| 196 | 196 | |
| 197 | 197 | // Setting up the namespace |
@@ -199,38 +199,38 @@ discard block |
||
| 199 | 199 | $route['namespace'] = NULL; |
| 200 | 200 | $group_namespace = implode('/', self::$namespace); |
| 201 | 201 | |
| 202 | - if(!is_null($group_namespace)) |
|
| 202 | + if (!is_null($group_namespace)) |
|
| 203 | 203 | $route['namespace'] = $group_namespace.'/'; |
| 204 | - if(isset($attr['namespace'])) |
|
| 204 | + if (isset($attr['namespace'])) |
|
| 205 | 205 | $route['namespace'] .= $attr['namespace']; |
| 206 | 206 | |
| 207 | 207 | $route['prefix'] = trim($route['prefix'], '/'); |
| 208 | - $route['namespace'] = trim($route['namespace'],'/'); |
|
| 208 | + $route['namespace'] = trim($route['namespace'], '/'); |
|
| 209 | 209 | |
| 210 | - if(empty($route['prefix'])) |
|
| 210 | + if (empty($route['prefix'])) |
|
| 211 | 211 | $route['prefix'] = NULL; |
| 212 | 212 | |
| 213 | - if(empty($route['namespace'])) |
|
| 213 | + if (empty($route['namespace'])) |
|
| 214 | 214 | $route['namespace'] = NULL; |
| 215 | 215 | |
| 216 | 216 | // Route middleware |
| 217 | 217 | $route['middleware'] = []; |
| 218 | 218 | $route['middleware'] = array_merge($route['middleware'], self::$middleware); |
| 219 | 219 | |
| 220 | - if(isset($attr['middleware'])) |
|
| 220 | + if (isset($attr['middleware'])) |
|
| 221 | 221 | { |
| 222 | - if(is_array($attr['middleware'])) |
|
| 222 | + if (is_array($attr['middleware'])) |
|
| 223 | 223 | { |
| 224 | - foreach($attr['middleware'] as $middleware) |
|
| 224 | + foreach ($attr['middleware'] as $middleware) |
|
| 225 | 225 | $route['middleware'][] = $middleware; # Group |
| 226 | 226 | } |
| 227 | - elseif( is_string($attr['middleware'])) |
|
| 227 | + elseif (is_string($attr['middleware'])) |
|
| 228 | 228 | { |
| 229 | 229 | $route['middleware'][] = $attr['middleware']; # Group |
| 230 | 230 | } |
| 231 | 231 | else |
| 232 | 232 | { |
| 233 | - show_error('Route middleware must be a string or an array',500,'Route error: bad middleware format'); |
|
| 233 | + show_error('Route middleware must be a string or an array', 500, 'Route error: bad middleware format'); |
|
| 234 | 234 | } |
| 235 | 235 | } |
| 236 | 236 | |
@@ -243,27 +243,27 @@ discard block |
||
| 243 | 243 | |
| 244 | 244 | $groupHideOriginals = end(self::$hideOriginals); |
| 245 | 245 | |
| 246 | - if($hideOriginal || $groupHideOriginals || ($compiledRoute->path != '' && $compiledRoute->path != '/' ) ) |
|
| 246 | + if ($hideOriginal || $groupHideOriginals || ($compiledRoute->path != '' && $compiledRoute->path != '/')) |
|
| 247 | 247 | { |
| 248 | 248 | $hiddenRoutePath = $controller.'/'.$method; |
| 249 | 249 | $hiddenRouteNamespace = ''; |
| 250 | 250 | |
| 251 | - if(!is_null($route['namespace'])) |
|
| 251 | + if (!is_null($route['namespace'])) |
|
| 252 | 252 | { |
| 253 | 253 | $hiddenRouteNamespace = $route['namespace'].'/'; |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | $hiddenRoutePath = $hiddenRouteNamespace.$hiddenRoutePath; |
| 257 | 257 | |
| 258 | - if($method == 'index') |
|
| 258 | + if ($method == 'index') |
|
| 259 | 259 | { |
| 260 | - self::$hiddenRoutes[] = [ $hiddenRouteNamespace.$controller => function(){ self::trigger404(); }]; |
|
| 260 | + self::$hiddenRoutes[] = [$hiddenRouteNamespace.$controller => function() { self::trigger404(); }]; |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - self::$hiddenRoutes[] = [$hiddenRoutePath => function(){ self::trigger404(); }]; |
|
| 263 | + self::$hiddenRoutes[] = [$hiddenRoutePath => function() { self::trigger404(); }]; |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - if(!$return) |
|
| 266 | + if (!$return) |
|
| 267 | 267 | { |
| 268 | 268 | self::$routes[] = (object) $route; |
| 269 | 269 | } |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | */ |
| 289 | 289 | public static function get($url, $attr, $hideOriginal = TRUE) |
| 290 | 290 | { |
| 291 | - self::add('GET', $url,$attr, $hideOriginal); |
|
| 291 | + self::add('GET', $url, $attr, $hideOriginal); |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | */ |
| 307 | 307 | public static function post($url, $attr, $hideOriginal = TRUE) |
| 308 | 308 | { |
| 309 | - self::add('POST', $url,$attr, $hideOriginal); |
|
| 309 | + self::add('POST', $url, $attr, $hideOriginal); |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | */ |
| 325 | 325 | public static function put($url, $attr, $hideOriginal = TRUE) |
| 326 | 326 | { |
| 327 | - self::add('PUT', $url,$attr, $hideOriginal); |
|
| 327 | + self::add('PUT', $url, $attr, $hideOriginal); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | */ |
| 343 | 343 | public static function patch($url, $attr, $hideOriginal = TRUE) |
| 344 | 344 | { |
| 345 | - self::add('PATCH', $url,$attr, $hideOriginal); |
|
| 345 | + self::add('PATCH', $url, $attr, $hideOriginal); |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | |
@@ -360,7 +360,7 @@ discard block |
||
| 360 | 360 | */ |
| 361 | 361 | public static function delete($url, $attr, $hideOriginal = TRUE) |
| 362 | 362 | { |
| 363 | - self::add('DELETE', $url,$attr, $hideOriginal); |
|
| 363 | + self::add('DELETE', $url, $attr, $hideOriginal); |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | */ |
| 379 | 379 | public static function any($url, $attr, $hideOriginal = TRUE) |
| 380 | 380 | { |
| 381 | - foreach(self::$http_verbs as $verb) |
|
| 381 | + foreach (self::$http_verbs as $verb) |
|
| 382 | 382 | { |
| 383 | 383 | $verb = strtolower($verb); |
| 384 | 384 | self::add($verb, $url, $attr, $hideOriginal); |
@@ -401,10 +401,10 @@ discard block |
||
| 401 | 401 | */ |
| 402 | 402 | public static function matches($verbs, $url, $attr, $hideOriginal = FALSE) |
| 403 | 403 | { |
| 404 | - if(!is_array($verbs)) |
|
| 404 | + if (!is_array($verbs)) |
|
| 405 | 405 | show_error('Route::matches() first argument must be an array of valid HTTP Verbs', 500, 'Route error: bad Route::matches() verb list'); |
| 406 | 406 | |
| 407 | - foreach($verbs as $verb) |
|
| 407 | + foreach ($verbs as $verb) |
|
| 408 | 408 | { |
| 409 | 409 | self::add($verb, $url, $attr, $hideOriginal); |
| 410 | 410 | } |
@@ -430,29 +430,29 @@ discard block |
||
| 430 | 430 | |
| 431 | 431 | $hideOriginal = FALSE; |
| 432 | 432 | |
| 433 | - if(isset($attr['namespace'])) |
|
| 433 | + if (isset($attr['namespace'])) |
|
| 434 | 434 | $base_attr['namespace'] = $attr['namespace']; |
| 435 | 435 | |
| 436 | - if(isset($attr['middleware'])) |
|
| 436 | + if (isset($attr['middleware'])) |
|
| 437 | 437 | $base_attr['middleware'] = $attr['middleware']; |
| 438 | 438 | |
| 439 | - if(isset($attr['hideOriginal'])) |
|
| 439 | + if (isset($attr['hideOriginal'])) |
|
| 440 | 440 | $hideOriginal = (bool) $attr['hideOriginal']; |
| 441 | 441 | |
| 442 | 442 | $base_attr['prefix'] = strtolower($name); |
| 443 | 443 | |
| 444 | - if(isset($attr['prefix'])) |
|
| 445 | - $base_attr['prefix'] = $attr['prefix']; |
|
| 444 | + if (isset($attr['prefix'])) |
|
| 445 | + $base_attr['prefix'] = $attr['prefix']; |
|
| 446 | 446 | |
| 447 | 447 | $only = []; |
| 448 | 448 | |
| 449 | 449 | $controller = strtolower($controller); |
| 450 | 450 | |
| 451 | - if(isset($attr['only']) && (is_array($attr['only']) || is_string($attr['only']))) |
|
| 451 | + if (isset($attr['only']) && (is_array($attr['only']) || is_string($attr['only']))) |
|
| 452 | 452 | { |
| 453 | - if(is_array($attr['only'])) |
|
| 453 | + if (is_array($attr['only'])) |
|
| 454 | 454 | { |
| 455 | - $only = $attr['only']; |
|
| 455 | + $only = $attr['only']; |
|
| 456 | 456 | } |
| 457 | 457 | else |
| 458 | 458 | { |
@@ -460,43 +460,43 @@ discard block |
||
| 460 | 460 | } |
| 461 | 461 | } |
| 462 | 462 | |
| 463 | - if(empty($only) || in_array('index', $only)) |
|
| 463 | + if (empty($only) || in_array('index', $only)) |
|
| 464 | 464 | { |
| 465 | - $route_attr = array_merge($base_attr, ['uses' => $controller.'@index', 'as' => $name.'.index']); |
|
| 465 | + $route_attr = array_merge($base_attr, ['uses' => $controller.'@index', 'as' => $name.'.index']); |
|
| 466 | 466 | self::get('/', $route_attr, $hideOriginal); |
| 467 | 467 | } |
| 468 | 468 | |
| 469 | - if(empty($only) || in_array('create', $only)) |
|
| 469 | + if (empty($only) || in_array('create', $only)) |
|
| 470 | 470 | { |
| 471 | 471 | $route_attr = array_merge($base_attr, ['uses' => $controller.'@create', 'as' => $name.'.create']); |
| 472 | 472 | self::get('create', $route_attr, $hideOriginal); |
| 473 | 473 | } |
| 474 | 474 | |
| 475 | - if(empty($only) || in_array('store', $only)) |
|
| 475 | + if (empty($only) || in_array('store', $only)) |
|
| 476 | 476 | { |
| 477 | 477 | $route_attr = array_merge($base_attr, ['uses' => $controller.'@store', 'as' => $name.'.store']); |
| 478 | 478 | self::post('/', $route_attr, $hideOriginal); |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | - if(empty($only) || in_array('show', $only)) |
|
| 481 | + if (empty($only) || in_array('show', $only)) |
|
| 482 | 482 | { |
| 483 | 483 | $route_attr = array_merge($base_attr, ['uses' => $controller.'@show', 'as' => $name.'.show']); |
| 484 | 484 | self::get('{slug}', $route_attr, $hideOriginal); |
| 485 | 485 | } |
| 486 | 486 | |
| 487 | - if(empty($only) || in_array('edit', $only)) |
|
| 487 | + if (empty($only) || in_array('edit', $only)) |
|
| 488 | 488 | { |
| 489 | 489 | $route_attr = array_merge($base_attr, ['uses' => $controller.'@edit', 'as' => $name.'.edit']); |
| 490 | 490 | self::get('{slug}/edit', $route_attr, $hideOriginal); |
| 491 | 491 | } |
| 492 | 492 | |
| 493 | - if(empty($only) || in_array('update', $only)) |
|
| 493 | + if (empty($only) || in_array('update', $only)) |
|
| 494 | 494 | { |
| 495 | 495 | $route_attr = array_merge($base_attr, ['uses' => $controller.'@update', 'as' => $name.'.update']); |
| 496 | 496 | self::matches(['PUT', 'PATCH'], '{slug}/update', $route_attr, $hideOriginal); |
| 497 | 497 | } |
| 498 | 498 | |
| 499 | - if(empty($only) || in_array('destroy', $only)) |
|
| 499 | + if (empty($only) || in_array('destroy', $only)) |
|
| 500 | 500 | { |
| 501 | 501 | $route_attr = array_merge($base_attr, ['uses' => $controller.'@destroy', 'as' => $name.'.destroy']); |
| 502 | 502 | self::delete('{slug}', $route_attr, $hideOriginal); |
@@ -519,33 +519,33 @@ discard block |
||
| 519 | 519 | $prefix = NULL; |
| 520 | 520 | $namespace = NULL; |
| 521 | 521 | |
| 522 | - if(!is_null($route->prefix)) |
|
| 522 | + if (!is_null($route->prefix)) |
|
| 523 | 523 | { |
| 524 | 524 | $prefix = $route->prefix; |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | - if(!is_null($route->namespace)) |
|
| 527 | + if (!is_null($route->namespace)) |
|
| 528 | 528 | { |
| 529 | 529 | $namespace = $route->namespace; |
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | $path = $route->path; |
| 533 | 533 | |
| 534 | - if(!is_null($prefix)) |
|
| 534 | + if (!is_null($prefix)) |
|
| 535 | 535 | $path = $prefix.'/'.$path; |
| 536 | 536 | |
| 537 | 537 | $controller = $route->controller.'/'.$route->method; |
| 538 | 538 | |
| 539 | - if(!is_null($namespace)) |
|
| 539 | + if (!is_null($namespace)) |
|
| 540 | 540 | $controller = $namespace.'/'.$controller; |
| 541 | 541 | |
| 542 | - $path = trim($path,'/'); |
|
| 543 | - $controller = trim($controller,'/'); |
|
| 542 | + $path = trim($path, '/'); |
|
| 543 | + $controller = trim($controller, '/'); |
|
| 544 | 544 | $baseController = $controller; |
| 545 | 545 | |
| 546 | 546 | $replaces = |
| 547 | 547 | [ |
| 548 | - '{\((.*)\):[a-zA-Z0-9-_]*(\?}|})' => '($1)', # Custom regular expression |
|
| 548 | + '{\((.*)\):[a-zA-Z0-9-_]*(\?}|})' => '($1)', # Custom regular expression |
|
| 549 | 549 | '{num:[a-zA-Z0-9-_]*(\?}|})' => '(:num)', # (:num) route |
| 550 | 550 | '{any:[a-zA-Z0-9-_]*(\?}|})' => '(:any)', # (:any) route |
| 551 | 551 | '{[a-zA-Z0-9-_]*(\?}|})' => '(:any)', # Everything else |
@@ -555,22 +555,22 @@ discard block |
||
| 555 | 555 | $basePath = ''; |
| 556 | 556 | |
| 557 | 557 | |
| 558 | - foreach(explode('/', $path) as $path_segment) |
|
| 558 | + foreach (explode('/', $path) as $path_segment) |
|
| 559 | 559 | { |
| 560 | - if(!preg_match('/^\{(.*)\}$/', $path_segment)) |
|
| 560 | + if (!preg_match('/^\{(.*)\}$/', $path_segment)) |
|
| 561 | 561 | { |
| 562 | - $basePath .= $path_segment . '/' ; |
|
| 562 | + $basePath .= $path_segment.'/'; |
|
| 563 | 563 | } |
| 564 | 564 | } |
| 565 | 565 | |
| 566 | - $basePath = trim($basePath,'/'); |
|
| 566 | + $basePath = trim($basePath, '/'); |
|
| 567 | 567 | |
| 568 | - foreach($replaces as $regex => $replace) |
|
| 568 | + foreach ($replaces as $regex => $replace) |
|
| 569 | 569 | { |
| 570 | 570 | $matches = []; |
| 571 | 571 | |
| 572 | 572 | //if(preg_match_all('/'.$regex.'/', $path, $matches )) |
| 573 | - if(preg_match_all('/\{(.*)\}/', $path, $matches )) |
|
| 573 | + if (preg_match_all('/\{(.*)\}/', $path, $matches)) |
|
| 574 | 574 | { |
| 575 | 575 | //$foundedArgs = $matches[0]; |
| 576 | 576 | $foundedArgs = explode('/', $matches[0][0]); |
@@ -586,24 +586,24 @@ discard block |
||
| 586 | 586 | $args['required'] = []; |
| 587 | 587 | $args['optional'] = []; |
| 588 | 588 | |
| 589 | - foreach($foundedArgs as $arg) |
|
| 589 | + foreach ($foundedArgs as $arg) |
|
| 590 | 590 | { |
| 591 | - if(substr($arg,-2) == '?}') |
|
| 591 | + if (substr($arg, -2) == '?}') |
|
| 592 | 592 | { |
| 593 | 593 | $args['optional'][] = $arg; |
| 594 | 594 | $argConstraint = TRUE; |
| 595 | 595 | } |
| 596 | 596 | else |
| 597 | 597 | { |
| 598 | - if($argConstraint) |
|
| 598 | + if ($argConstraint) |
|
| 599 | 599 | show_error('Optional route path argument not valid at this position', 500, 'Route error'); |
| 600 | 600 | $args['required'][] = $arg; |
| 601 | 601 | } |
| 602 | 602 | } |
| 603 | 603 | |
| 604 | - if(count($foundedArgs) > 0) |
|
| 604 | + if (count($foundedArgs) > 0) |
|
| 605 | 605 | { |
| 606 | - for($i = 0; $i < count($foundedArgs); $i++) |
|
| 606 | + for ($i = 0; $i < count($foundedArgs); $i++) |
|
| 607 | 607 | { |
| 608 | 608 | $controller .= '/$'.($i + 1); |
| 609 | 609 | } |
@@ -631,14 +631,14 @@ discard block |
||
| 631 | 631 | { |
| 632 | 632 | $routes = array(); |
| 633 | 633 | |
| 634 | - foreach(self::$routes as $index => $route) |
|
| 634 | + foreach (self::$routes as $index => $route) |
|
| 635 | 635 | { |
| 636 | 636 | $compiled = self::compileRoute($route); |
| 637 | 637 | |
| 638 | 638 | $backtrackingPath = ''; |
| 639 | 639 | $backtrackingRoute = ''; |
| 640 | 640 | |
| 641 | - if( count($compiled->args['optional']) > 0 ) |
|
| 641 | + if (count($compiled->args['optional']) > 0) |
|
| 642 | 642 | { |
| 643 | 643 | $e_path = explode('/', $compiled->path); |
| 644 | 644 | $e_route = explode('/', $compiled->route); |
@@ -646,54 +646,54 @@ discard block |
||
| 646 | 646 | $basePath = $compiled->basePath; |
| 647 | 647 | $baseRoute = $compiled->baseRoute; |
| 648 | 648 | |
| 649 | - $a = count(explode('/',$basePath)); |
|
| 649 | + $a = count(explode('/', $basePath)); |
|
| 650 | 650 | |
| 651 | - for($r = 0; $r < count($compiled->args['required']); $r++) |
|
| 651 | + for ($r = 0; $r < count($compiled->args['required']); $r++) |
|
| 652 | 652 | { |
| 653 | - $basePath .= '/' . $e_path[ $a + $r ]; |
|
| 654 | - $baseRoute .= '/' . '$' . ($r + 1); |
|
| 653 | + $basePath .= '/'.$e_path[$a + $r]; |
|
| 654 | + $baseRoute .= '/'.'$'.($r + 1); |
|
| 655 | 655 | } |
| 656 | 656 | |
| 657 | - $a = count(explode('/',$basePath)); |
|
| 657 | + $a = count(explode('/', $basePath)); |
|
| 658 | 658 | $b = ($r + 1); |
| 659 | 659 | |
| 660 | 660 | $backtracking = []; |
| 661 | 661 | |
| 662 | - for($o = 0; $o <= count($compiled->args['optional']); $o++) |
|
| 662 | + for ($o = 0; $o <= count($compiled->args['optional']); $o++) |
|
| 663 | 663 | { |
| 664 | 664 | $backtrackingPath = $basePath; |
| 665 | 665 | $backtrackingRoute = $baseRoute; |
| 666 | 666 | |
| 667 | - for($c = 0; $c < $o ; $c++) |
|
| 667 | + for ($c = 0; $c < $o; $c++) |
|
| 668 | 668 | { |
| 669 | - $backtrackingPath .= '/' . $e_path[$a + $c - 1]; |
|
| 670 | - $backtrackingRoute .= '/' . '$' . ($b + $c); |
|
| 669 | + $backtrackingPath .= '/'.$e_path[$a + $c - 1]; |
|
| 670 | + $backtrackingRoute .= '/'.'$'.($b + $c); |
|
| 671 | 671 | } |
| 672 | 672 | |
| 673 | - $backtracking[$o] = [ 'path' => $backtrackingPath, 'route' => $backtrackingRoute ]; |
|
| 673 | + $backtracking[$o] = ['path' => $backtrackingPath, 'route' => $backtrackingRoute]; |
|
| 674 | 674 | } |
| 675 | 675 | |
| 676 | - foreach($backtracking as $b_route) |
|
| 676 | + foreach ($backtracking as $b_route) |
|
| 677 | 677 | { |
| 678 | 678 | $b_compiled = self::compileRoute($route); |
| 679 | 679 | $b_args = array_merge($b_compiled->args['required'], $b_compiled->args['optional']); |
| 680 | 680 | $b_route_path = $b_route['path']; |
| 681 | 681 | |
| 682 | - foreach($b_args as $arg) |
|
| 682 | + foreach ($b_args as $arg) |
|
| 683 | 683 | { |
| 684 | 684 | $b_route_path = preg_replace('/\((.*?)\)/', $arg, $b_route_path, 1); |
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | self::add($route->verb, $b_route_path, ['uses' => $route->controller.'@'.$route->method]); |
| 688 | 688 | |
| 689 | - if( !isset($routes[$b_route['path']]) || $route->verb == 'GET' ) |
|
| 689 | + if (!isset($routes[$b_route['path']]) || $route->verb == 'GET') |
|
| 690 | 690 | { |
| 691 | 691 | $routes[$b_route['path']] = $b_route['route']; |
| 692 | 692 | } |
| 693 | 693 | } |
| 694 | 694 | } |
| 695 | 695 | |
| 696 | - if( !isset($routes[$compiled->path]) || $route->verb == 'GET' ) |
|
| 696 | + if (!isset($routes[$compiled->path]) || $route->verb == 'GET') |
|
| 697 | 697 | { |
| 698 | 698 | $routes[$compiled->path] = $compiled->route; |
| 699 | 699 | } |
@@ -701,16 +701,16 @@ discard block |
||
| 701 | 701 | self::$routes[$index] = (object) $route; |
| 702 | 702 | } |
| 703 | 703 | |
| 704 | - foreach(self::$hiddenRoutes as $route) |
|
| 704 | + foreach (self::$hiddenRoutes as $route) |
|
| 705 | 705 | { |
| 706 | 706 | $path = key($route); |
| 707 | 707 | $_404 = $route[$path]; |
| 708 | 708 | |
| 709 | - if(!isset($routes[$path])) |
|
| 709 | + if (!isset($routes[$path])) |
|
| 710 | 710 | $routes[$path] = $_404; |
| 711 | 711 | } |
| 712 | 712 | |
| 713 | - if(is_null(self::$defaultController)) |
|
| 713 | + if (is_null(self::$defaultController)) |
|
| 714 | 714 | show_error('You must specify a home route: Route::home() as default controller!', 500, 'Route error: missing default controller'); |
| 715 | 715 | |
| 716 | 716 | $defaultController = self::$defaultController->compiled; |
@@ -718,7 +718,7 @@ discard block |
||
| 718 | 718 | |
| 719 | 719 | $routes['default_controller'] = $defaultController; |
| 720 | 720 | |
| 721 | - if(is_null(self::$_404page)) |
|
| 721 | + if (is_null(self::$_404page)) |
|
| 722 | 722 | { |
| 723 | 723 | $routes['404_override'] = ''; |
| 724 | 724 | } |
@@ -746,20 +746,20 @@ discard block |
||
| 746 | 746 | */ |
| 747 | 747 | public static function group($attr, $routes) |
| 748 | 748 | { |
| 749 | - if(!is_array($attr)) |
|
| 749 | + if (!is_array($attr)) |
|
| 750 | 750 | show_error('Group attribute must be a valid array'); |
| 751 | 751 | |
| 752 | - if(!isset($attr['prefix'])) |
|
| 752 | + if (!isset($attr['prefix'])) |
|
| 753 | 753 | show_error('You must specify an prefix!'); |
| 754 | 754 | |
| 755 | 755 | self::$prefix[] = $attr['prefix']; |
| 756 | 756 | |
| 757 | - if(isset($attr['namespace'])) |
|
| 757 | + if (isset($attr['namespace'])) |
|
| 758 | 758 | { |
| 759 | 759 | self::$namespace[] = $attr['namespace']; |
| 760 | 760 | } |
| 761 | 761 | |
| 762 | - if(isset($attr['hideOriginals']) && $attr['hideOriginals'] === TRUE) |
|
| 762 | + if (isset($attr['hideOriginals']) && $attr['hideOriginals'] === TRUE) |
|
| 763 | 763 | { |
| 764 | 764 | self::$hideOriginals[] = TRUE; |
| 765 | 765 | } |
@@ -768,13 +768,13 @@ discard block |
||
| 768 | 768 | self::$hideOriginals[] = FALSE; |
| 769 | 769 | } |
| 770 | 770 | |
| 771 | - if(isset($attr['middleware'])) |
|
| 771 | + if (isset($attr['middleware'])) |
|
| 772 | 772 | { |
| 773 | - if(is_array($attr['middleware']) || is_string($attr['middleware'])) |
|
| 773 | + if (is_array($attr['middleware']) || is_string($attr['middleware'])) |
|
| 774 | 774 | { |
| 775 | - if(is_array($attr['middleware']) && !empty($attr['middleware'])) |
|
| 775 | + if (is_array($attr['middleware']) && !empty($attr['middleware'])) |
|
| 776 | 776 | { |
| 777 | - foreach($attr['middleware'] as $middleware) |
|
| 777 | + foreach ($attr['middleware'] as $middleware) |
|
| 778 | 778 | self::$middleware[] = $middleware; |
| 779 | 779 | } |
| 780 | 780 | else |
@@ -818,16 +818,16 @@ discard block |
||
| 818 | 818 | 'as' => $as |
| 819 | 819 | ]; |
| 820 | 820 | |
| 821 | - if(!is_null($attr) && !is_array($attr)) |
|
| 822 | - show_error('Default controller attributes must be an array',500,'Route error: bad attribute type'); |
|
| 821 | + if (!is_null($attr) && !is_array($attr)) |
|
| 822 | + show_error('Default controller attributes must be an array', 500, 'Route error: bad attribute type'); |
|
| 823 | 823 | |
| 824 | - if(!is_null($attr)) |
|
| 825 | - $routeAttr = array_merge($routeAttr,$attr); |
|
| 824 | + if (!is_null($attr)) |
|
| 825 | + $routeAttr = array_merge($routeAttr, $attr); |
|
| 826 | 826 | |
| 827 | - if(isset($attr['prefix'])) |
|
| 828 | - show_error('Default controller may not have a prefix!',500,'Route error: prefix not allowed'); |
|
| 827 | + if (isset($attr['prefix'])) |
|
| 828 | + show_error('Default controller may not have a prefix!', 500, 'Route error: prefix not allowed'); |
|
| 829 | 829 | |
| 830 | - self::$defaultController = self::$routes[] = self::add('GET', '/', ['uses' => $controller, 'as' => $as],TRUE, TRUE); |
|
| 830 | + self::$defaultController = self::$routes[] = self::add('GET', '/', ['uses' => $controller, 'as' => $as], TRUE, TRUE); |
|
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | |
@@ -841,16 +841,16 @@ discard block |
||
| 841 | 841 | */ |
| 842 | 842 | public static function getRoutes($verb = NULL) |
| 843 | 843 | { |
| 844 | - if(is_null($verb)) |
|
| 844 | + if (is_null($verb)) |
|
| 845 | 845 | { |
| 846 | 846 | return self::$routes; |
| 847 | 847 | } |
| 848 | 848 | else |
| 849 | 849 | { |
| 850 | 850 | $routes = []; |
| 851 | - foreach(self::$routes as $route) |
|
| 851 | + foreach (self::$routes as $route) |
|
| 852 | 852 | { |
| 853 | - if($route->verb == $verb) |
|
| 853 | + if ($route->verb == $verb) |
|
| 854 | 854 | $routes[] = $route; |
| 855 | 855 | } |
| 856 | 856 | return $routes; |
@@ -890,45 +890,45 @@ discard block |
||
| 890 | 890 | $args = func_get_args(); |
| 891 | 891 | unset($args[0]); |
| 892 | 892 | |
| 893 | - foreach(self::$routes as $route) |
|
| 893 | + foreach (self::$routes as $route) |
|
| 894 | 894 | { |
| 895 | - if($route->name == $search) |
|
| 895 | + if ($route->name == $search) |
|
| 896 | 896 | { |
| 897 | 897 | $founded = $route; |
| 898 | 898 | } |
| 899 | 899 | } |
| 900 | 900 | |
| 901 | - if(!is_null($founded)) |
|
| 901 | + if (!is_null($founded)) |
|
| 902 | 902 | { |
| 903 | 903 | $routeArgs = self::compileRoute($founded)->args; |
| 904 | 904 | $routeArgCount = count($routeArgs['required']) + count($routeArgs['optional']); |
| 905 | 905 | $routeReqArgCount = count($routeArgs['required']); |
| 906 | 906 | |
| 907 | - if(count($args) < $routeReqArgCount) |
|
| 907 | + if (count($args) < $routeReqArgCount) |
|
| 908 | 908 | { |
| 909 | 909 | $missingArgs = $routeReqArgCount - count($args); |
| 910 | 910 | throw new \Exception('Missing '.$missingArgs.' required argument'.($missingArgs != 1 ? 's' : '').' for route "'.$founded->name.'"'); |
| 911 | 911 | } |
| 912 | - if(count($args) > $routeArgCount) |
|
| 912 | + if (count($args) > $routeArgCount) |
|
| 913 | 913 | { |
| 914 | 914 | throw new \Exception('The route "'.$founded->name.'" expects maximum '.$routeArgCount.' argument'.($routeArgCount != 1 ? 's' : '').', '.count($args).' provided'); |
| 915 | 915 | } |
| 916 | 916 | |
| 917 | 917 | $path = self::compileRoute($founded)->path; |
| 918 | 918 | |
| 919 | - foreach($args as $replacement) |
|
| 919 | + foreach ($args as $replacement) |
|
| 920 | 920 | { |
| 921 | 921 | $path = preg_replace('/\((.*?)\)/', $replacement, $path, 1); |
| 922 | 922 | } |
| 923 | 923 | |
| 924 | - $argsLeft = $routeArgCount - count($args); |
|
| 924 | + $argsLeft = $routeArgCount - count($args); |
|
| 925 | 925 | |
| 926 | - for($i = $argsLeft; $i >= 0; $i--) |
|
| 926 | + for ($i = $argsLeft; $i >= 0; $i--) |
|
| 927 | 927 | { |
| 928 | 928 | $path = preg_replace('/\((.*?)\)/', '', $path, 1); |
| 929 | 929 | } |
| 930 | 930 | |
| 931 | - return base_url(trim($path,'/')); |
|
| 931 | + return base_url(trim($path, '/')); |
|
| 932 | 932 | } |
| 933 | 933 | |
| 934 | 934 | throw new \Exception('The route "'.$search.'" is not defined'); |
@@ -947,17 +947,17 @@ discard block |
||
| 947 | 947 | */ |
| 948 | 948 | public static function getRouteByPath($path, $requestMethod = NULL) |
| 949 | 949 | { |
| 950 | - if(is_null($requestMethod)) |
|
| 950 | + if (is_null($requestMethod)) |
|
| 951 | 951 | $requestMethod = $_SERVER['REQUEST_METHOD']; |
| 952 | 952 | |
| 953 | 953 | $routes = self::getRoutes($requestMethod); |
| 954 | 954 | |
| 955 | - if(empty($routes)) |
|
| 955 | + if (empty($routes)) |
|
| 956 | 956 | return FALSE; |
| 957 | 957 | |
| 958 | 958 | $path = trim($path); |
| 959 | 959 | |
| 960 | - if($path == '') |
|
| 960 | + if ($path == '') |
|
| 961 | 961 | return self::$defaultController; |
| 962 | 962 | |
| 963 | 963 | $wildcards = |
@@ -974,17 +974,17 @@ discard block |
||
| 974 | 974 | '(.*)' |
| 975 | 975 | ]; |
| 976 | 976 | |
| 977 | - foreach( ['exact' , 'regex'] as $mode) |
|
| 977 | + foreach (['exact', 'regex'] as $mode) |
|
| 978 | 978 | { |
| 979 | - foreach( [ $path, $path.'/index' ] as $findPath ) |
|
| 979 | + foreach ([$path, $path.'/index'] as $findPath) |
|
| 980 | 980 | { |
| 981 | - foreach($routes as $route) |
|
| 981 | + foreach ($routes as $route) |
|
| 982 | 982 | { |
| 983 | 983 | $compiledPath = key($route->compiled); |
| 984 | 984 | |
| 985 | - if($mode == 'exact') |
|
| 985 | + if ($mode == 'exact') |
|
| 986 | 986 | { |
| 987 | - if($findPath == $compiledPath) |
|
| 987 | + if ($findPath == $compiledPath) |
|
| 988 | 988 | return $route; |
| 989 | 989 | } |
| 990 | 990 | else |
@@ -992,30 +992,30 @@ discard block |
||
| 992 | 992 | $e_findPath = explode('/', $findPath); |
| 993 | 993 | $e_compiledPath = explode('/', $compiledPath); |
| 994 | 994 | |
| 995 | - if( count($e_findPath) == count($e_compiledPath)) |
|
| 995 | + if (count($e_findPath) == count($e_compiledPath)) |
|
| 996 | 996 | { |
| 997 | 997 | //var_dump($findPath, $compiledPath); |
| 998 | 998 | |
| 999 | 999 | $valid = TRUE; |
| 1000 | 1000 | $seachUntil = NULL; |
| 1001 | 1001 | |
| 1002 | - for($i = 0; $i < count($e_findPath); $i++) |
|
| 1002 | + for ($i = 0; $i < count($e_findPath); $i++) |
|
| 1003 | 1003 | { |
| 1004 | 1004 | $reg = preg_replace($wildcards, $replaces, $e_compiledPath[$i]); |
| 1005 | 1005 | |
| 1006 | 1006 | $valid = (bool) preg_match('#^'.$reg.'$#', $e_findPath[$i]); |
| 1007 | 1007 | |
| 1008 | - if($valid && is_null($seachUntil)) |
|
| 1008 | + if ($valid && is_null($seachUntil)) |
|
| 1009 | 1009 | $seachUntil = $i; |
| 1010 | 1010 | } |
| 1011 | 1011 | |
| 1012 | - if($valid) |
|
| 1012 | + if ($valid) |
|
| 1013 | 1013 | { |
| 1014 | - for($i = 0; $i < $seachUntil; $i++) |
|
| 1014 | + for ($i = 0; $i < $seachUntil; $i++) |
|
| 1015 | 1015 | $valid = $e_findPath[$i] == $e_compiledPath[$i]; |
| 1016 | 1016 | } |
| 1017 | 1017 | |
| 1018 | - if($valid) |
|
| 1018 | + if ($valid) |
|
| 1019 | 1019 | return $route; |
| 1020 | 1020 | } |
| 1021 | 1021 | } |
@@ -1048,12 +1048,12 @@ discard block |
||
| 1048 | 1048 | $args = []; |
| 1049 | 1049 | $n_args = 1; |
| 1050 | 1050 | |
| 1051 | - for($s = 0; $s < count($r_seg); $s++) |
|
| 1051 | + for ($s = 0; $s < count($r_seg); $s++) |
|
| 1052 | 1052 | { |
| 1053 | - if(!isset($p_seg[$s])) |
|
| 1053 | + if (!isset($p_seg[$s])) |
|
| 1054 | 1054 | continue; |
| 1055 | 1055 | |
| 1056 | - if($r_seg[$s] != $p_seg[$s]) |
|
| 1056 | + if ($r_seg[$s] != $p_seg[$s]) |
|
| 1057 | 1057 | { |
| 1058 | 1058 | $args['$'.$n_args] = $p_seg[$s]; |
| 1059 | 1059 | $n_args++; |
@@ -1141,9 +1141,9 @@ discard block |
||
| 1141 | 1141 | */ |
| 1142 | 1142 | public static function trigger404() |
| 1143 | 1143 | { |
| 1144 | - if( !is_null(self::$_404page) ) |
|
| 1144 | + if (!is_null(self::$_404page)) |
|
| 1145 | 1145 | { |
| 1146 | - header( 'Location: ' . config_item('base_url') . self::$_404page->path ); |
|
| 1146 | + header('Location: '.config_item('base_url').self::$_404page->path); |
|
| 1147 | 1147 | die; |
| 1148 | 1148 | } |
| 1149 | 1149 | |
@@ -147,11 +147,13 @@ discard block |
||
| 147 | 147 | $controller = $parsedController[1]; |
| 148 | 148 | $method = $parsedController[2]; |
| 149 | 149 | |
| 150 | - if(!is_string($path)) |
|
| 151 | - show_error('Route path must be a string ', 500, 'Route error: bad route path'); |
|
| 150 | + if(!is_string($path)) { |
|
| 151 | + show_error('Route path must be a string ', 500, 'Route error: bad route path'); |
|
| 152 | + } |
|
| 152 | 153 | |
| 153 | - if(!is_string($verb)) |
|
| 154 | - show_error('Route HTTP Verb must be a string', 500, 'Route error: bad verb type'); |
|
| 154 | + if(!is_string($verb)) { |
|
| 155 | + show_error('Route HTTP Verb must be a string', 500, 'Route error: bad verb type'); |
|
| 156 | + } |
|
| 155 | 157 | |
| 156 | 158 | $verb = strtoupper($verb); |
| 157 | 159 | |
@@ -177,8 +179,7 @@ discard block |
||
| 177 | 179 | if(isset($attr['as'])) |
| 178 | 180 | { |
| 179 | 181 | $route['name'] = $attr['as']; |
| 180 | - } |
|
| 181 | - else |
|
| 182 | + } else |
|
| 182 | 183 | { |
| 183 | 184 | $route['name'] = NULL; |
| 184 | 185 | } |
@@ -188,30 +189,36 @@ discard block |
||
| 188 | 189 | $route['prefix'] = NULL; |
| 189 | 190 | $group_prefix = implode('/', self::$prefix); |
| 190 | 191 | |
| 191 | - if($group_prefix) |
|
| 192 | - $route['prefix'] = $group_prefix.'/'; |
|
| 192 | + if($group_prefix) { |
|
| 193 | + $route['prefix'] = $group_prefix.'/'; |
|
| 194 | + } |
|
| 193 | 195 | |
| 194 | - if(isset($attr['prefix'])) |
|
| 195 | - $route['prefix'] .= $attr['prefix']; |
|
| 196 | + if(isset($attr['prefix'])) { |
|
| 197 | + $route['prefix'] .= $attr['prefix']; |
|
| 198 | + } |
|
| 196 | 199 | |
| 197 | 200 | // Setting up the namespace |
| 198 | 201 | |
| 199 | 202 | $route['namespace'] = NULL; |
| 200 | 203 | $group_namespace = implode('/', self::$namespace); |
| 201 | 204 | |
| 202 | - if(!is_null($group_namespace)) |
|
| 203 | - $route['namespace'] = $group_namespace.'/'; |
|
| 204 | - if(isset($attr['namespace'])) |
|
| 205 | - $route['namespace'] .= $attr['namespace']; |
|
| 205 | + if(!is_null($group_namespace)) { |
|
| 206 | + $route['namespace'] = $group_namespace.'/'; |
|
| 207 | + } |
|
| 208 | + if(isset($attr['namespace'])) { |
|
| 209 | + $route['namespace'] .= $attr['namespace']; |
|
| 210 | + } |
|
| 206 | 211 | |
| 207 | 212 | $route['prefix'] = trim($route['prefix'], '/'); |
| 208 | 213 | $route['namespace'] = trim($route['namespace'],'/'); |
| 209 | 214 | |
| 210 | - if(empty($route['prefix'])) |
|
| 211 | - $route['prefix'] = NULL; |
|
| 215 | + if(empty($route['prefix'])) { |
|
| 216 | + $route['prefix'] = NULL; |
|
| 217 | + } |
|
| 212 | 218 | |
| 213 | - if(empty($route['namespace'])) |
|
| 214 | - $route['namespace'] = NULL; |
|
| 219 | + if(empty($route['namespace'])) { |
|
| 220 | + $route['namespace'] = NULL; |
|
| 221 | + } |
|
| 215 | 222 | |
| 216 | 223 | // Route middleware |
| 217 | 224 | $route['middleware'] = []; |
@@ -221,14 +228,14 @@ discard block |
||
| 221 | 228 | { |
| 222 | 229 | if(is_array($attr['middleware'])) |
| 223 | 230 | { |
| 224 | - foreach($attr['middleware'] as $middleware) |
|
| 225 | - $route['middleware'][] = $middleware; # Group |
|
| 226 | - } |
|
| 227 | - elseif( is_string($attr['middleware'])) |
|
| 231 | + foreach($attr['middleware'] as $middleware) { |
|
| 232 | + $route['middleware'][] = $middleware; |
|
| 233 | + } |
|
| 234 | + # Group |
|
| 235 | + } elseif( is_string($attr['middleware'])) |
|
| 228 | 236 | { |
| 229 | 237 | $route['middleware'][] = $attr['middleware']; # Group |
| 230 | - } |
|
| 231 | - else |
|
| 238 | + } else |
|
| 232 | 239 | { |
| 233 | 240 | show_error('Route middleware must be a string or an array',500,'Route error: bad middleware format'); |
| 234 | 241 | } |
@@ -266,8 +273,7 @@ discard block |
||
| 266 | 273 | if(!$return) |
| 267 | 274 | { |
| 268 | 275 | self::$routes[] = (object) $route; |
| 269 | - } |
|
| 270 | - else |
|
| 276 | + } else |
|
| 271 | 277 | { |
| 272 | 278 | return (object) $route; |
| 273 | 279 | } |
@@ -401,8 +407,9 @@ discard block |
||
| 401 | 407 | */ |
| 402 | 408 | public static function matches($verbs, $url, $attr, $hideOriginal = FALSE) |
| 403 | 409 | { |
| 404 | - if(!is_array($verbs)) |
|
| 405 | - show_error('Route::matches() first argument must be an array of valid HTTP Verbs', 500, 'Route error: bad Route::matches() verb list'); |
|
| 410 | + if(!is_array($verbs)) { |
|
| 411 | + show_error('Route::matches() first argument must be an array of valid HTTP Verbs', 500, 'Route error: bad Route::matches() verb list'); |
|
| 412 | + } |
|
| 406 | 413 | |
| 407 | 414 | foreach($verbs as $verb) |
| 408 | 415 | { |
@@ -430,19 +437,23 @@ discard block |
||
| 430 | 437 | |
| 431 | 438 | $hideOriginal = FALSE; |
| 432 | 439 | |
| 433 | - if(isset($attr['namespace'])) |
|
| 434 | - $base_attr['namespace'] = $attr['namespace']; |
|
| 440 | + if(isset($attr['namespace'])) { |
|
| 441 | + $base_attr['namespace'] = $attr['namespace']; |
|
| 442 | + } |
|
| 435 | 443 | |
| 436 | - if(isset($attr['middleware'])) |
|
| 437 | - $base_attr['middleware'] = $attr['middleware']; |
|
| 444 | + if(isset($attr['middleware'])) { |
|
| 445 | + $base_attr['middleware'] = $attr['middleware']; |
|
| 446 | + } |
|
| 438 | 447 | |
| 439 | - if(isset($attr['hideOriginal'])) |
|
| 440 | - $hideOriginal = (bool) $attr['hideOriginal']; |
|
| 448 | + if(isset($attr['hideOriginal'])) { |
|
| 449 | + $hideOriginal = (bool) $attr['hideOriginal']; |
|
| 450 | + } |
|
| 441 | 451 | |
| 442 | 452 | $base_attr['prefix'] = strtolower($name); |
| 443 | 453 | |
| 444 | - if(isset($attr['prefix'])) |
|
| 445 | - $base_attr['prefix'] = $attr['prefix']; |
|
| 454 | + if(isset($attr['prefix'])) { |
|
| 455 | + $base_attr['prefix'] = $attr['prefix']; |
|
| 456 | + } |
|
| 446 | 457 | |
| 447 | 458 | $only = []; |
| 448 | 459 | |
@@ -453,8 +464,7 @@ discard block |
||
| 453 | 464 | if(is_array($attr['only'])) |
| 454 | 465 | { |
| 455 | 466 | $only = $attr['only']; |
| 456 | - } |
|
| 457 | - else |
|
| 467 | + } else |
|
| 458 | 468 | { |
| 459 | 469 | $only[] = $attr['only']; |
| 460 | 470 | } |
@@ -531,13 +541,15 @@ discard block |
||
| 531 | 541 | |
| 532 | 542 | $path = $route->path; |
| 533 | 543 | |
| 534 | - if(!is_null($prefix)) |
|
| 535 | - $path = $prefix.'/'.$path; |
|
| 544 | + if(!is_null($prefix)) { |
|
| 545 | + $path = $prefix.'/'.$path; |
|
| 546 | + } |
|
| 536 | 547 | |
| 537 | 548 | $controller = $route->controller.'/'.$route->method; |
| 538 | 549 | |
| 539 | - if(!is_null($namespace)) |
|
| 540 | - $controller = $namespace.'/'.$controller; |
|
| 550 | + if(!is_null($namespace)) { |
|
| 551 | + $controller = $namespace.'/'.$controller; |
|
| 552 | + } |
|
| 541 | 553 | |
| 542 | 554 | $path = trim($path,'/'); |
| 543 | 555 | $controller = trim($controller,'/'); |
@@ -592,11 +604,11 @@ discard block |
||
| 592 | 604 | { |
| 593 | 605 | $args['optional'][] = $arg; |
| 594 | 606 | $argConstraint = TRUE; |
| 595 | - } |
|
| 596 | - else |
|
| 607 | + } else |
|
| 597 | 608 | { |
| 598 | - if($argConstraint) |
|
| 599 | - show_error('Optional route path argument not valid at this position', 500, 'Route error'); |
|
| 609 | + if($argConstraint) { |
|
| 610 | + show_error('Optional route path argument not valid at this position', 500, 'Route error'); |
|
| 611 | + } |
|
| 600 | 612 | $args['required'][] = $arg; |
| 601 | 613 | } |
| 602 | 614 | } |
@@ -706,12 +718,14 @@ discard block |
||
| 706 | 718 | $path = key($route); |
| 707 | 719 | $_404 = $route[$path]; |
| 708 | 720 | |
| 709 | - if(!isset($routes[$path])) |
|
| 710 | - $routes[$path] = $_404; |
|
| 721 | + if(!isset($routes[$path])) { |
|
| 722 | + $routes[$path] = $_404; |
|
| 723 | + } |
|
| 711 | 724 | } |
| 712 | 725 | |
| 713 | - if(is_null(self::$defaultController)) |
|
| 714 | - show_error('You must specify a home route: Route::home() as default controller!', 500, 'Route error: missing default controller'); |
|
| 726 | + if(is_null(self::$defaultController)) { |
|
| 727 | + show_error('You must specify a home route: Route::home() as default controller!', 500, 'Route error: missing default controller'); |
|
| 728 | + } |
|
| 715 | 729 | |
| 716 | 730 | $defaultController = self::$defaultController->compiled; |
| 717 | 731 | $defaultController = $defaultController[key($defaultController)]; |
@@ -721,8 +735,7 @@ discard block |
||
| 721 | 735 | if(is_null(self::$_404page)) |
| 722 | 736 | { |
| 723 | 737 | $routes['404_override'] = ''; |
| 724 | - } |
|
| 725 | - else |
|
| 738 | + } else |
|
| 726 | 739 | { |
| 727 | 740 | $routes['404_override'] = self::$_404page->controller; |
| 728 | 741 | } |
@@ -746,11 +759,13 @@ discard block |
||
| 746 | 759 | */ |
| 747 | 760 | public static function group($attr, $routes) |
| 748 | 761 | { |
| 749 | - if(!is_array($attr)) |
|
| 750 | - show_error('Group attribute must be a valid array'); |
|
| 762 | + if(!is_array($attr)) { |
|
| 763 | + show_error('Group attribute must be a valid array'); |
|
| 764 | + } |
|
| 751 | 765 | |
| 752 | - if(!isset($attr['prefix'])) |
|
| 753 | - show_error('You must specify an prefix!'); |
|
| 766 | + if(!isset($attr['prefix'])) { |
|
| 767 | + show_error('You must specify an prefix!'); |
|
| 768 | + } |
|
| 754 | 769 | |
| 755 | 770 | self::$prefix[] = $attr['prefix']; |
| 756 | 771 | |
@@ -762,8 +777,7 @@ discard block |
||
| 762 | 777 | if(isset($attr['hideOriginals']) && $attr['hideOriginals'] === TRUE) |
| 763 | 778 | { |
| 764 | 779 | self::$hideOriginals[] = TRUE; |
| 765 | - } |
|
| 766 | - else |
|
| 780 | + } else |
|
| 767 | 781 | { |
| 768 | 782 | self::$hideOriginals[] = FALSE; |
| 769 | 783 | } |
@@ -774,15 +788,14 @@ discard block |
||
| 774 | 788 | { |
| 775 | 789 | if(is_array($attr['middleware']) && !empty($attr['middleware'])) |
| 776 | 790 | { |
| 777 | - foreach($attr['middleware'] as $middleware) |
|
| 778 | - self::$middleware[] = $middleware; |
|
| 779 | - } |
|
| 780 | - else |
|
| 791 | + foreach($attr['middleware'] as $middleware) { |
|
| 792 | + self::$middleware[] = $middleware; |
|
| 793 | + } |
|
| 794 | + } else |
|
| 781 | 795 | { |
| 782 | 796 | self::$middleware[] = $attr['middleware']; |
| 783 | 797 | } |
| 784 | - } |
|
| 785 | - else |
|
| 798 | + } else |
|
| 786 | 799 | { |
| 787 | 800 | show_error('Group middleware must be an array o a string', 500, 'Route error'); |
| 788 | 801 | } |
@@ -818,14 +831,17 @@ discard block |
||
| 818 | 831 | 'as' => $as |
| 819 | 832 | ]; |
| 820 | 833 | |
| 821 | - if(!is_null($attr) && !is_array($attr)) |
|
| 822 | - show_error('Default controller attributes must be an array',500,'Route error: bad attribute type'); |
|
| 834 | + if(!is_null($attr) && !is_array($attr)) { |
|
| 835 | + show_error('Default controller attributes must be an array',500,'Route error: bad attribute type'); |
|
| 836 | + } |
|
| 823 | 837 | |
| 824 | - if(!is_null($attr)) |
|
| 825 | - $routeAttr = array_merge($routeAttr,$attr); |
|
| 838 | + if(!is_null($attr)) { |
|
| 839 | + $routeAttr = array_merge($routeAttr,$attr); |
|
| 840 | + } |
|
| 826 | 841 | |
| 827 | - if(isset($attr['prefix'])) |
|
| 828 | - show_error('Default controller may not have a prefix!',500,'Route error: prefix not allowed'); |
|
| 842 | + if(isset($attr['prefix'])) { |
|
| 843 | + show_error('Default controller may not have a prefix!',500,'Route error: prefix not allowed'); |
|
| 844 | + } |
|
| 829 | 845 | |
| 830 | 846 | self::$defaultController = self::$routes[] = self::add('GET', '/', ['uses' => $controller, 'as' => $as],TRUE, TRUE); |
| 831 | 847 | } |
@@ -844,14 +860,14 @@ discard block |
||
| 844 | 860 | if(is_null($verb)) |
| 845 | 861 | { |
| 846 | 862 | return self::$routes; |
| 847 | - } |
|
| 848 | - else |
|
| 863 | + } else |
|
| 849 | 864 | { |
| 850 | 865 | $routes = []; |
| 851 | 866 | foreach(self::$routes as $route) |
| 852 | 867 | { |
| 853 | - if($route->verb == $verb) |
|
| 854 | - $routes[] = $route; |
|
| 868 | + if($route->verb == $verb) { |
|
| 869 | + $routes[] = $route; |
|
| 870 | + } |
|
| 855 | 871 | } |
| 856 | 872 | return $routes; |
| 857 | 873 | } |
@@ -947,18 +963,21 @@ discard block |
||
| 947 | 963 | */ |
| 948 | 964 | public static function getRouteByPath($path, $requestMethod = NULL) |
| 949 | 965 | { |
| 950 | - if(is_null($requestMethod)) |
|
| 951 | - $requestMethod = $_SERVER['REQUEST_METHOD']; |
|
| 966 | + if(is_null($requestMethod)) { |
|
| 967 | + $requestMethod = $_SERVER['REQUEST_METHOD']; |
|
| 968 | + } |
|
| 952 | 969 | |
| 953 | 970 | $routes = self::getRoutes($requestMethod); |
| 954 | 971 | |
| 955 | - if(empty($routes)) |
|
| 956 | - return FALSE; |
|
| 972 | + if(empty($routes)) { |
|
| 973 | + return FALSE; |
|
| 974 | + } |
|
| 957 | 975 | |
| 958 | 976 | $path = trim($path); |
| 959 | 977 | |
| 960 | - if($path == '') |
|
| 961 | - return self::$defaultController; |
|
| 978 | + if($path == '') { |
|
| 979 | + return self::$defaultController; |
|
| 980 | + } |
|
| 962 | 981 | |
| 963 | 982 | $wildcards = |
| 964 | 983 | [ |
@@ -984,10 +1003,10 @@ discard block |
||
| 984 | 1003 | |
| 985 | 1004 | if($mode == 'exact') |
| 986 | 1005 | { |
| 987 | - if($findPath == $compiledPath) |
|
| 988 | - return $route; |
|
| 989 | - } |
|
| 990 | - else |
|
| 1006 | + if($findPath == $compiledPath) { |
|
| 1007 | + return $route; |
|
| 1008 | + } |
|
| 1009 | + } else |
|
| 991 | 1010 | { |
| 992 | 1011 | $e_findPath = explode('/', $findPath); |
| 993 | 1012 | $e_compiledPath = explode('/', $compiledPath); |
@@ -1005,18 +1024,21 @@ discard block |
||
| 1005 | 1024 | |
| 1006 | 1025 | $valid = (bool) preg_match('#^'.$reg.'$#', $e_findPath[$i]); |
| 1007 | 1026 | |
| 1008 | - if($valid && is_null($seachUntil)) |
|
| 1009 | - $seachUntil = $i; |
|
| 1027 | + if($valid && is_null($seachUntil)) { |
|
| 1028 | + $seachUntil = $i; |
|
| 1029 | + } |
|
| 1010 | 1030 | } |
| 1011 | 1031 | |
| 1012 | 1032 | if($valid) |
| 1013 | 1033 | { |
| 1014 | - for($i = 0; $i < $seachUntil; $i++) |
|
| 1015 | - $valid = $e_findPath[$i] == $e_compiledPath[$i]; |
|
| 1034 | + for($i = 0; $i < $seachUntil; $i++) { |
|
| 1035 | + $valid = $e_findPath[$i] == $e_compiledPath[$i]; |
|
| 1036 | + } |
|
| 1016 | 1037 | } |
| 1017 | 1038 | |
| 1018 | - if($valid) |
|
| 1019 | - return $route; |
|
| 1039 | + if($valid) { |
|
| 1040 | + return $route; |
|
| 1041 | + } |
|
| 1020 | 1042 | } |
| 1021 | 1043 | } |
| 1022 | 1044 | } |
@@ -1050,8 +1072,9 @@ discard block |
||
| 1050 | 1072 | |
| 1051 | 1073 | for($s = 0; $s < count($r_seg); $s++) |
| 1052 | 1074 | { |
| 1053 | - if(!isset($p_seg[$s])) |
|
| 1054 | - continue; |
|
| 1075 | + if(!isset($p_seg[$s])) { |
|
| 1076 | + continue; |
|
| 1077 | + } |
|
| 1055 | 1078 | |
| 1056 | 1079 | if($r_seg[$s] != $p_seg[$s]) |
| 1057 | 1080 | { |
@@ -120,7 +120,7 @@ |
||
| 120 | 120 | // Redirect to 404 if not enough parameters provided |
| 121 | 121 | |
| 122 | 122 | if(count($path_args) < count($route_args['required'])) |
| 123 | - redirect(Route::get404()->path); |
|
| 123 | + redirect(Route::get404()->path); |
|
| 124 | 124 | |
| 125 | 125 | if(count($path_args) == 0) |
| 126 | 126 | { |
@@ -64,19 +64,19 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | // FIXME: Solve ambiguity here! POST with _method="GET" makes no sense |
| 66 | 66 | |
| 67 | - if(isset($_POST['_method']) && in_array(strtoupper($_POST['_method']), $validMethods , TRUE)) |
|
| 67 | + if (isset($_POST['_method']) && in_array(strtoupper($_POST['_method']), $validMethods, TRUE)) |
|
| 68 | 68 | $formMethod = strtoupper($_POST['_method']); |
| 69 | 69 | |
| 70 | - if(is_null($formMethod)) |
|
| 70 | + if (is_null($formMethod)) |
|
| 71 | 71 | { |
| 72 | 72 | $this->requestMethod = $requestMethod; |
| 73 | 73 | } |
| 74 | 74 | else |
| 75 | 75 | { |
| 76 | - if($requestMethod == 'POST') |
|
| 76 | + if ($requestMethod == 'POST') |
|
| 77 | 77 | $this->requestMethod = $formMethod; |
| 78 | 78 | |
| 79 | - if(!$this->CI->input->is_ajax_request() && $this->requestMethod == 'HEAD') |
|
| 79 | + if (!$this->CI->input->is_ajax_request() && $this->requestMethod == 'HEAD') |
|
| 80 | 80 | $this->requestMethod = 'POST'; |
| 81 | 81 | } |
| 82 | 82 | } |
@@ -90,14 +90,14 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | public function run() |
| 92 | 92 | { |
| 93 | - if(!$this->route) |
|
| 93 | + if (!$this->route) |
|
| 94 | 94 | { |
| 95 | 95 | //if(is_null(Route::get404())) |
| 96 | 96 | // show_404(); |
| 97 | 97 | |
| 98 | - if(Route::get404()->controller != get_class($this->CI)) |
|
| 98 | + if (Route::get404()->controller != get_class($this->CI)) |
|
| 99 | 99 | { |
| 100 | - if(ENVIRONMENT != 'production') |
|
| 100 | + if (ENVIRONMENT != 'production') |
|
| 101 | 101 | { |
| 102 | 102 | show_error('The request method '.$this->requestMethod.' is not allowed to view the resource', 403, 'Forbidden method'); |
| 103 | 103 | } |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | } |
| 111 | 111 | else |
| 112 | 112 | { |
| 113 | - if(method_exists($this->CI,$this->route->method)) |
|
| 113 | + if (method_exists($this->CI, $this->route->method)) |
|
| 114 | 114 | { |
| 115 | 115 | $path_args = Route::getRouteArgs($this->route, self::$uri_string); |
| 116 | 116 | $route_args = Route::compileRoute($this->route)->args; |
@@ -119,16 +119,16 @@ discard block |
||
| 119 | 119 | |
| 120 | 120 | // Redirect to 404 if not enough parameters provided |
| 121 | 121 | |
| 122 | - if(count($path_args) < count($route_args['required'])) |
|
| 122 | + if (count($path_args) < count($route_args['required'])) |
|
| 123 | 123 | redirect(Route::get404()->path); |
| 124 | 124 | |
| 125 | - if(count($path_args) == 0) |
|
| 125 | + if (count($path_args) == 0) |
|
| 126 | 126 | { |
| 127 | 127 | $this->CI->{$this->route->method}(); |
| 128 | 128 | } |
| 129 | 129 | else |
| 130 | 130 | { |
| 131 | - call_user_func_array( [$this->CI, $this->route->method], array_values($path_args) ); |
|
| 131 | + call_user_func_array([$this->CI, $this->route->method], array_values($path_args)); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | } |
| 140 | 140 | else |
| 141 | 141 | { |
| 142 | - if(ENVIRONMENT != 'production') |
|
| 142 | + if (ENVIRONMENT != 'production') |
|
| 143 | 143 | { |
| 144 | 144 | show_error('The method '.$this->route->controller.'::'.$this->route->method.'() does not exists', 500, 'Method not found'); |
| 145 | 145 | } |
@@ -64,20 +64,22 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | // FIXME: Solve ambiguity here! POST with _method="GET" makes no sense |
| 66 | 66 | |
| 67 | - if(isset($_POST['_method']) && in_array(strtoupper($_POST['_method']), $validMethods , TRUE)) |
|
| 68 | - $formMethod = strtoupper($_POST['_method']); |
|
| 67 | + if(isset($_POST['_method']) && in_array(strtoupper($_POST['_method']), $validMethods , TRUE)) { |
|
| 68 | + $formMethod = strtoupper($_POST['_method']); |
|
| 69 | + } |
|
| 69 | 70 | |
| 70 | 71 | if(is_null($formMethod)) |
| 71 | 72 | { |
| 72 | 73 | $this->requestMethod = $requestMethod; |
| 73 | - } |
|
| 74 | - else |
|
| 74 | + } else |
|
| 75 | 75 | { |
| 76 | - if($requestMethod == 'POST') |
|
| 77 | - $this->requestMethod = $formMethod; |
|
| 76 | + if($requestMethod == 'POST') { |
|
| 77 | + $this->requestMethod = $formMethod; |
|
| 78 | + } |
|
| 78 | 79 | |
| 79 | - if(!$this->CI->input->is_ajax_request() && $this->requestMethod == 'HEAD') |
|
| 80 | - $this->requestMethod = 'POST'; |
|
| 80 | + if(!$this->CI->input->is_ajax_request() && $this->requestMethod == 'HEAD') { |
|
| 81 | + $this->requestMethod = 'POST'; |
|
| 82 | + } |
|
| 81 | 83 | } |
| 82 | 84 | } |
| 83 | 85 | |
@@ -100,15 +102,13 @@ discard block |
||
| 100 | 102 | if(ENVIRONMENT != 'production') |
| 101 | 103 | { |
| 102 | 104 | show_error('The request method '.$this->requestMethod.' is not allowed to view the resource', 403, 'Forbidden method'); |
| 103 | - } |
|
| 104 | - else |
|
| 105 | + } else |
|
| 105 | 106 | { |
| 106 | 107 | //redirect(Route::get404()->path); |
| 107 | 108 | Route::trigger404(); |
| 108 | 109 | } |
| 109 | 110 | } |
| 110 | - } |
|
| 111 | - else |
|
| 111 | + } else |
|
| 112 | 112 | { |
| 113 | 113 | if(method_exists($this->CI,$this->route->method)) |
| 114 | 114 | { |
@@ -119,14 +119,14 @@ discard block |
||
| 119 | 119 | |
| 120 | 120 | // Redirect to 404 if not enough parameters provided |
| 121 | 121 | |
| 122 | - if(count($path_args) < count($route_args['required'])) |
|
| 123 | - redirect(Route::get404()->path); |
|
| 122 | + if(count($path_args) < count($route_args['required'])) { |
|
| 123 | + redirect(Route::get404()->path); |
|
| 124 | + } |
|
| 124 | 125 | |
| 125 | 126 | if(count($path_args) == 0) |
| 126 | 127 | { |
| 127 | 128 | $this->CI->{$this->route->method}(); |
| 128 | - } |
|
| 129 | - else |
|
| 129 | + } else |
|
| 130 | 130 | { |
| 131 | 131 | call_user_func_array( [$this->CI, $this->route->method], array_values($path_args) ); |
| 132 | 132 | } |
@@ -136,14 +136,12 @@ discard block |
||
| 136 | 136 | |
| 137 | 137 | $this->CI->output->_display(); |
| 138 | 138 | exit(0); |
| 139 | - } |
|
| 140 | - else |
|
| 139 | + } else |
|
| 141 | 140 | { |
| 142 | 141 | if(ENVIRONMENT != 'production') |
| 143 | 142 | { |
| 144 | 143 | show_error('The method '.$this->route->controller.'::'.$this->route->method.'() does not exists', 500, 'Method not found'); |
| 145 | - } |
|
| 146 | - else |
|
| 144 | + } else |
|
| 147 | 145 | { |
| 148 | 146 | //redirect(Route::get404()->path); |
| 149 | 147 | Route::trigger404(); |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | public function __construct() |
| 52 | 52 | { |
| 53 | - $this->CI =& self::$instance; |
|
| 53 | + $this->CI = & self::$instance; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | public static function init() |
| 65 | 65 | { |
| 66 | - self::$instance =& get_instance(); |
|
| 66 | + self::$instance = & get_instance(); |
|
| 67 | 67 | self::$uri_string = self::$instance->router->uri->uri_string(); |
| 68 | 68 | |
| 69 | 69 | // Execute user defined middleware: |
@@ -92,16 +92,16 @@ discard block |
||
| 92 | 92 | $_run = array(); |
| 93 | 93 | |
| 94 | 94 | // Current route middleware |
| 95 | - if($currentRoute !== FALSE) |
|
| 95 | + if ($currentRoute !== FALSE) |
|
| 96 | 96 | { |
| 97 | - foreach($currentRoute->middleware as $middleware) |
|
| 97 | + foreach ($currentRoute->middleware as $middleware) |
|
| 98 | 98 | { |
| 99 | - if(!in_array($middleware,$_run)) |
|
| 99 | + if (!in_array($middleware, $_run)) |
|
| 100 | 100 | $_run[] = $middleware; |
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - foreach($_run as $middleware) |
|
| 104 | + foreach ($_run as $middleware) |
|
| 105 | 105 | { |
| 106 | 106 | self::runMiddleware($middleware); |
| 107 | 107 | } |
@@ -125,30 +125,30 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | $middlewareName = ucfirst($middlewareName).'_middleware'; |
| 127 | 127 | |
| 128 | - if(!file_exists($middlewareDir)) |
|
| 128 | + if (!file_exists($middlewareDir)) |
|
| 129 | 129 | show_error('Unable to find (or read) the middleware folder: "'.$middlewareDir.'"'); |
| 130 | 130 | |
| 131 | - $runMiddleware = $middlewareDir.$middlewareName.'.php'; |
|
| 131 | + $runMiddleware = $middlewareDir.$middlewareName.'.php'; |
|
| 132 | 132 | |
| 133 | - if(!file_exists($runMiddleware)) |
|
| 133 | + if (!file_exists($runMiddleware)) |
|
| 134 | 134 | show_error('Unable to find (or read) the middleware "'.$runMiddleware.'"'); |
| 135 | 135 | |
| 136 | 136 | require $runMiddleware; |
| 137 | 137 | |
| 138 | - if(!class_exists($middlewareName)) |
|
| 138 | + if (!class_exists($middlewareName)) |
|
| 139 | 139 | show_error('Class "'.$middlewareName.'" not found'); |
| 140 | 140 | |
| 141 | 141 | $middleware = new $middlewareName(); |
| 142 | 142 | |
| 143 | 143 | // Call the current controller __beforeMiddleware() method, if exists: |
| 144 | - if(method_exists(self::$instance, '_beforeMiddleware')) |
|
| 144 | + if (method_exists(self::$instance, '_beforeMiddleware')) |
|
| 145 | 145 | self::$instance->_beforeMiddleware(); |
| 146 | 146 | |
| 147 | 147 | // Run the middleware |
| 148 | 148 | $middleware->run(); |
| 149 | 149 | |
| 150 | 150 | // Call the current controller _afterMiddleware() method, if exists: |
| 151 | - if(method_exists(self::$instance, '_afterMiddleware')) |
|
| 151 | + if (method_exists(self::$instance, '_afterMiddleware')) |
|
| 152 | 152 | self::$instance->_afterMiddleware(); |
| 153 | 153 | |
| 154 | 154 | } |
@@ -96,8 +96,9 @@ discard block |
||
| 96 | 96 | { |
| 97 | 97 | foreach($currentRoute->middleware as $middleware) |
| 98 | 98 | { |
| 99 | - if(!in_array($middleware,$_run)) |
|
| 100 | - $_run[] = $middleware; |
|
| 99 | + if(!in_array($middleware,$_run)) { |
|
| 100 | + $_run[] = $middleware; |
|
| 101 | + } |
|
| 101 | 102 | } |
| 102 | 103 | } |
| 103 | 104 | |
@@ -125,31 +126,36 @@ discard block |
||
| 125 | 126 | |
| 126 | 127 | $middlewareName = ucfirst($middlewareName).'_middleware'; |
| 127 | 128 | |
| 128 | - if(!file_exists($middlewareDir)) |
|
| 129 | - show_error('Unable to find (or read) the middleware folder: "'.$middlewareDir.'"'); |
|
| 129 | + if(!file_exists($middlewareDir)) { |
|
| 130 | + show_error('Unable to find (or read) the middleware folder: "'.$middlewareDir.'"'); |
|
| 131 | + } |
|
| 130 | 132 | |
| 131 | 133 | $runMiddleware = $middlewareDir.$middlewareName.'.php'; |
| 132 | 134 | |
| 133 | - if(!file_exists($runMiddleware)) |
|
| 134 | - show_error('Unable to find (or read) the middleware "'.$runMiddleware.'"'); |
|
| 135 | + if(!file_exists($runMiddleware)) { |
|
| 136 | + show_error('Unable to find (or read) the middleware "'.$runMiddleware.'"'); |
|
| 137 | + } |
|
| 135 | 138 | |
| 136 | 139 | require $runMiddleware; |
| 137 | 140 | |
| 138 | - if(!class_exists($middlewareName)) |
|
| 139 | - show_error('Class "'.$middlewareName.'" not found'); |
|
| 141 | + if(!class_exists($middlewareName)) { |
|
| 142 | + show_error('Class "'.$middlewareName.'" not found'); |
|
| 143 | + } |
|
| 140 | 144 | |
| 141 | 145 | $middleware = new $middlewareName(); |
| 142 | 146 | |
| 143 | 147 | // Call the current controller __beforeMiddleware() method, if exists: |
| 144 | - if(method_exists(self::$instance, '_beforeMiddleware')) |
|
| 145 | - self::$instance->_beforeMiddleware(); |
|
| 148 | + if(method_exists(self::$instance, '_beforeMiddleware')) { |
|
| 149 | + self::$instance->_beforeMiddleware(); |
|
| 150 | + } |
|
| 146 | 151 | |
| 147 | 152 | // Run the middleware |
| 148 | 153 | $middleware->run(); |
| 149 | 154 | |
| 150 | 155 | // Call the current controller _afterMiddleware() method, if exists: |
| 151 | - if(method_exists(self::$instance, '_afterMiddleware')) |
|
| 152 | - self::$instance->_afterMiddleware(); |
|
| 156 | + if(method_exists(self::$instance, '_afterMiddleware')) { |
|
| 157 | + self::$instance->_afterMiddleware(); |
|
| 158 | + } |
|
| 153 | 159 | |
| 154 | 160 | } |
| 155 | 161 | } |