@@ -120,7 +120,6 @@ discard block |
||
| 120 | 120 | * Generic method to add a improved route |
| 121 | 121 | * |
| 122 | 122 | * @param mixed $verb String or array of string of valid HTTP Verbs that will be accepted in this route |
| 123 | - * @param mixed $url String or array of strings that will trigger this route |
|
| 124 | 123 | * @param array $attr Associative array of route attributes |
| 125 | 124 | * @param bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside |
| 126 | 125 | * |
@@ -274,7 +273,7 @@ discard block |
||
| 274 | 273 | /** |
| 275 | 274 | * Adds a GET route, alias of Route::add('GET',$url,$attr,$hideOriginal) |
| 276 | 275 | * |
| 277 | - * @param mixed $url String or array of strings that will trigger this route |
|
| 276 | + * @param string $url String or array of strings that will trigger this route |
|
| 278 | 277 | * @param array $attr Associative array of route attributes |
| 279 | 278 | * @param bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside |
| 280 | 279 | * |
@@ -291,7 +290,7 @@ discard block |
||
| 291 | 290 | /** |
| 292 | 291 | * Adds a POST route, alias of Route::add('POST',$url,$attr,$hideOriginal) |
| 293 | 292 | * |
| 294 | - * @param mixed $url String or array of strings that will trigger this route |
|
| 293 | + * @param string $url String or array of strings that will trigger this route |
|
| 295 | 294 | * @param array $attr Associative array of route attributes |
| 296 | 295 | * @param bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside |
| 297 | 296 | * |
@@ -342,7 +341,7 @@ discard block |
||
| 342 | 341 | /** |
| 343 | 342 | * Adds a DELETE route, alias of Route::add('DELETE',$url,$attr,$hideOriginal) |
| 344 | 343 | * |
| 345 | - * @param mixed $url String or array of strings that will trigger this route |
|
| 344 | + * @param string $url String or array of strings that will trigger this route |
|
| 346 | 345 | * @param array $attr Associative array of route attributes |
| 347 | 346 | * @param bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside |
| 348 | 347 | * |
@@ -380,8 +379,8 @@ discard block |
||
| 380 | 379 | /** |
| 381 | 380 | * Adds a list of routes with the verbs contained in $verbs, alias of Route::add($verbs,$url,$attr,$hideOriginal) |
| 382 | 381 | * |
| 383 | - * @param mixed $verb String or array of string of valid HTTP Verbs that will be accepted in this route |
|
| 384 | - * @param mixed $url String or array of strings that will trigger this route |
|
| 382 | + * @param string[] $verbs String or array of string of valid HTTP Verbs that will be accepted in this route |
|
| 383 | + * @param string $url String or array of strings that will trigger this route |
|
| 385 | 384 | * @param array $attr Associative array of route attributes |
| 386 | 385 | * @param bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside |
| 387 | 386 | * |
@@ -415,7 +414,6 @@ discard block |
||
| 415 | 414 | * |
| 416 | 415 | * PLEASE NOTE: This is NOT a crud generator, just a bundle of predefined routes. |
| 417 | 416 | * |
| 418 | - * @param string $url String or array of strings that will trigger this route |
|
| 419 | 417 | * @param string $controller Controller name (only controller name) |
| 420 | 418 | * @param array $attr Associative array of route attributes |
| 421 | 419 | * |
@@ -702,10 +700,6 @@ discard block |
||
| 702 | 700 | /** |
| 703 | 701 | * Creates the 'default_controller' key in CodeIgniter's route array |
| 704 | 702 | * |
| 705 | - * @param string $route controller/method name |
|
| 706 | - * @param string $alias (Optional) alias of the default controller |
|
| 707 | - * |
|
| 708 | - * Due a CodeIgniter limitations, this route MAY NOT be a directory. |
|
| 709 | 703 | * |
| 710 | 704 | * @return void |
| 711 | 705 | * |
@@ -763,7 +757,7 @@ discard block |
||
| 763 | 757 | /** |
| 764 | 758 | * Get all the improved routes defined |
| 765 | 759 | * |
| 766 | - * @return array List of all defined routes |
|
| 760 | + * @return Route List of all defined routes |
|
| 767 | 761 | * |
| 768 | 762 | * @access public |
| 769 | 763 | * @static |
@@ -830,7 +824,8 @@ discard block |
||
| 830 | 824 | * This is the 'reverse' process of the improved routing, it'll take the current |
| 831 | 825 | * uri string and attempts to find a CodeIgniter route that matches with his pattern |
| 832 | 826 | * |
| 833 | - * @param string $search The current uri string |
|
| 827 | + * @param Middleware $path |
|
| 828 | + * @param string $requestMethod |
|
| 834 | 829 | */ |
| 835 | 830 | public static function getRouteByPath($path, $requestMethod = NULL) |
| 836 | 831 | { |
@@ -879,7 +874,7 @@ discard block |
||
| 879 | 874 | /** |
| 880 | 875 | * Returns an array with the valid HTTP Verbs used in routes |
| 881 | 876 | * |
| 882 | - * @return array |
|
| 877 | + * @return Route |
|
| 883 | 878 | * |
| 884 | 879 | * @access public |
| 885 | 880 | * @static |
@@ -149,11 +149,13 @@ discard block |
||
| 149 | 149 | $controller = $parsedController[1]; |
| 150 | 150 | $method = $parsedController[2]; |
| 151 | 151 | |
| 152 | - if(!is_string($path)) |
|
| 153 | - show_error('Route path must be a string ', 500, 'Route error: bad route path'); |
|
| 152 | + if(!is_string($path)) { |
|
| 153 | + show_error('Route path must be a string ', 500, 'Route error: bad route path'); |
|
| 154 | + } |
|
| 154 | 155 | |
| 155 | - if(!is_string($verb)) |
|
| 156 | - show_error('Route HTTP Verb must be a string', 500, 'Route error: bad verb type'); |
|
| 156 | + if(!is_string($verb)) { |
|
| 157 | + show_error('Route HTTP Verb must be a string', 500, 'Route error: bad verb type'); |
|
| 158 | + } |
|
| 157 | 159 | |
| 158 | 160 | $verb = strtoupper($verb); |
| 159 | 161 | |
@@ -182,38 +184,47 @@ discard block |
||
| 182 | 184 | if(isset($attr['as'])) |
| 183 | 185 | { |
| 184 | 186 | $route['name'] = $attr['as']; |
| 185 | - } |
|
| 186 | - else |
|
| 187 | + } else |
|
| 187 | 188 | { |
| 188 | 189 | $route['name'] = NULL; |
| 189 | 190 | } |
| 190 | 191 | |
| 191 | 192 | $route['prefix'] = NULL; |
| 192 | 193 | |
| 193 | - if(!is_null(self::$prefix)) |
|
| 194 | - $route['prefix'] = self::$prefix; # Group |
|
| 195 | - if(isset($attr['prefix'])) |
|
| 196 | - $route['prefix'] = $attr['prefix']; # Specific (will overwrite group prefix) |
|
| 194 | + if(!is_null(self::$prefix)) { |
|
| 195 | + $route['prefix'] = self::$prefix; |
|
| 196 | + } |
|
| 197 | + # Group |
|
| 198 | + if(isset($attr['prefix'])) { |
|
| 199 | + $route['prefix'] = $attr['prefix']; |
|
| 200 | + } |
|
| 201 | + # Specific (will overwrite group prefix) |
|
| 197 | 202 | |
| 198 | 203 | $route['namespace'] = NULL; |
| 199 | 204 | |
| 200 | - if(!is_null(self::$namespace)) |
|
| 201 | - $route['namespace'] = self::$namespace; # Group |
|
| 202 | - if(isset($attr['namespace'])) |
|
| 203 | - $route['namespace'] = $attr['namespace']; # Specific (will overwrite group namespace) |
|
| 205 | + if(!is_null(self::$namespace)) { |
|
| 206 | + $route['namespace'] = self::$namespace; |
|
| 207 | + } |
|
| 208 | + # Group |
|
| 209 | + if(isset($attr['namespace'])) { |
|
| 210 | + $route['namespace'] = $attr['namespace']; |
|
| 211 | + } |
|
| 212 | + # Specific (will overwrite group namespace) |
|
| 204 | 213 | |
| 205 | 214 | # Removing trailing slashes |
| 206 | 215 | if(!is_null($route['prefix'])) |
| 207 | 216 | { |
| 208 | 217 | $route['prefix'] = trim($route['prefix'],'/'); |
| 209 | - if($route['prefix'] == '') |
|
| 210 | - $route['prefix'] = NULL; |
|
| 218 | + if($route['prefix'] == '') { |
|
| 219 | + $route['prefix'] = NULL; |
|
| 220 | + } |
|
| 211 | 221 | } |
| 212 | 222 | if(!is_null($route['namespace'])) |
| 213 | 223 | { |
| 214 | 224 | $route['namespace'] = trim($route['namespace'],'/'); |
| 215 | - if($route['namespace'] == '') |
|
| 216 | - $route['namespace'] = NULL; |
|
| 225 | + if($route['namespace'] == '') { |
|
| 226 | + $route['namespace'] = NULL; |
|
| 227 | + } |
|
| 217 | 228 | } |
| 218 | 229 | |
| 219 | 230 | $route['middleware'] = array(); |
@@ -222,14 +233,14 @@ discard block |
||
| 222 | 233 | { |
| 223 | 234 | if(is_array($attr['middleware'])) |
| 224 | 235 | { |
| 225 | - foreach($attr['middleware'] as $middleware) |
|
| 226 | - $route['middleware'][] = $middleware; # Group |
|
| 227 | - } |
|
| 228 | - elseif( is_string($attr['middleware'])) |
|
| 236 | + foreach($attr['middleware'] as $middleware) { |
|
| 237 | + $route['middleware'][] = $middleware; |
|
| 238 | + } |
|
| 239 | + # Group |
|
| 240 | + } elseif( is_string($attr['middleware'])) |
|
| 229 | 241 | { |
| 230 | 242 | $route['middleware'][] = $attr['middleware']; # Group |
| 231 | - } |
|
| 232 | - else |
|
| 243 | + } else |
|
| 233 | 244 | { |
| 234 | 245 | show_error('Route middleware must be a string or an array',500,'Route error: bad middleware format'); |
| 235 | 246 | } |
@@ -264,8 +275,7 @@ discard block |
||
| 264 | 275 | if(!$return) |
| 265 | 276 | { |
| 266 | 277 | self::$routes[] = (object) $route; |
| 267 | - } |
|
| 268 | - else |
|
| 278 | + } else |
|
| 269 | 279 | { |
| 270 | 280 | return (object) $route; |
| 271 | 281 | } |
@@ -392,8 +402,9 @@ discard block |
||
| 392 | 402 | */ |
| 393 | 403 | public static function matches($verbs, $url, $attr, $hideOriginal = FALSE) |
| 394 | 404 | { |
| 395 | - if(!is_array($verbs)) |
|
| 396 | - show_error('Route::matches() first argument must be an array of valid HTTP Verbs', 500, 'Route error: bad Route::matches() verb list'); |
|
| 405 | + if(!is_array($verbs)) { |
|
| 406 | + show_error('Route::matches() first argument must be an array of valid HTTP Verbs', 500, 'Route error: bad Route::matches() verb list'); |
|
| 407 | + } |
|
| 397 | 408 | |
| 398 | 409 | foreach($verbs as $verb) |
| 399 | 410 | { |
@@ -430,17 +441,21 @@ discard block |
||
| 430 | 441 | |
| 431 | 442 | $hideOriginal = FALSE; |
| 432 | 443 | |
| 433 | - if(isset($attr['namespace'])) |
|
| 434 | - $base_attr['namespace'] = $attr['namespace']; |
|
| 444 | + if(isset($attr['namespace'])) { |
|
| 445 | + $base_attr['namespace'] = $attr['namespace']; |
|
| 446 | + } |
|
| 435 | 447 | |
| 436 | - if(isset($attr['middleware'])) |
|
| 437 | - $base_attr['middleware'] = $attr['middleware']; |
|
| 448 | + if(isset($attr['middleware'])) { |
|
| 449 | + $base_attr['middleware'] = $attr['middleware']; |
|
| 450 | + } |
|
| 438 | 451 | |
| 439 | - if(isset($attr['hideOriginal'])) |
|
| 440 | - $hideOriginal = (bool) $attr['hideOriginal']; |
|
| 452 | + if(isset($attr['hideOriginal'])) { |
|
| 453 | + $hideOriginal = (bool) $attr['hideOriginal']; |
|
| 454 | + } |
|
| 441 | 455 | |
| 442 | - if(isset($attr['prefix'])) |
|
| 443 | - $base_attr['prefix'] = $attr['prefix']; |
|
| 456 | + if(isset($attr['prefix'])) { |
|
| 457 | + $base_attr['prefix'] = $attr['prefix']; |
|
| 458 | + } |
|
| 444 | 459 | |
| 445 | 460 | $only = array(); |
| 446 | 461 | |
@@ -449,8 +464,7 @@ discard block |
||
| 449 | 464 | if(is_array($attr['only'])) |
| 450 | 465 | { |
| 451 | 466 | $only = strtolower($attr['only']); |
| 452 | - } |
|
| 453 | - else |
|
| 467 | + } else |
|
| 454 | 468 | { |
| 455 | 469 | $only[] = strtolower($attr['only']); |
| 456 | 470 | } |
@@ -526,16 +540,19 @@ discard block |
||
| 526 | 540 | |
| 527 | 541 | $path = $route->path; |
| 528 | 542 | |
| 529 | - if(!is_null($prefix)) |
|
| 530 | - $path = $prefix.'/'.$path; |
|
| 543 | + if(!is_null($prefix)) { |
|
| 544 | + $path = $prefix.'/'.$path; |
|
| 545 | + } |
|
| 531 | 546 | |
| 532 | - if(substr($path, 0, 1) == "/" && strlen($path) > 1) |
|
| 533 | - $path = substr($path,1); |
|
| 547 | + if(substr($path, 0, 1) == "/" && strlen($path) > 1) { |
|
| 548 | + $path = substr($path,1); |
|
| 549 | + } |
|
| 534 | 550 | |
| 535 | 551 | $controller = $route->controller.'/'.$route->method; |
| 536 | 552 | |
| 537 | - if(!is_null($namespace)) |
|
| 538 | - $controller = $namespace.'/'.$controller; |
|
| 553 | + if(!is_null($namespace)) { |
|
| 554 | + $controller = $namespace.'/'.$controller; |
|
| 555 | + } |
|
| 539 | 556 | |
| 540 | 557 | $replaces = |
| 541 | 558 | [ |
@@ -601,12 +618,14 @@ discard block |
||
| 601 | 618 | $path = key($route); |
| 602 | 619 | $_404 = $route[$path]; |
| 603 | 620 | |
| 604 | - if(!isset($routes[$path])) |
|
| 605 | - $routes[$path] = $_404; |
|
| 621 | + if(!isset($routes[$path])) { |
|
| 622 | + $routes[$path] = $_404; |
|
| 623 | + } |
|
| 606 | 624 | } |
| 607 | 625 | |
| 608 | - if(is_null(self::$defaultController)) |
|
| 609 | - show_error('You must specify a home route: Route::home() as default controller!', 500, 'Route error: missing default controller'); |
|
| 626 | + if(is_null(self::$defaultController)) { |
|
| 627 | + show_error('You must specify a home route: Route::home() as default controller!', 500, 'Route error: missing default controller'); |
|
| 628 | + } |
|
| 610 | 629 | |
| 611 | 630 | $defaultController = self::$defaultController->compiled; |
| 612 | 631 | $defaultController = $defaultController[key($defaultController)]; |
@@ -632,11 +651,13 @@ discard block |
||
| 632 | 651 | */ |
| 633 | 652 | public static function group($attr, $routes) |
| 634 | 653 | { |
| 635 | - if(!is_array($attr)) |
|
| 636 | - show_error('Group attribute must be a valid array'); |
|
| 654 | + if(!is_array($attr)) { |
|
| 655 | + show_error('Group attribute must be a valid array'); |
|
| 656 | + } |
|
| 637 | 657 | |
| 638 | - if(!isset($attr['prefix'])) |
|
| 639 | - show_error('You must specify an prefix!'); |
|
| 658 | + if(!isset($attr['prefix'])) { |
|
| 659 | + show_error('You must specify an prefix!'); |
|
| 660 | + } |
|
| 640 | 661 | |
| 641 | 662 | self::$prefix = $attr['prefix']; |
| 642 | 663 | |
@@ -648,8 +669,7 @@ discard block |
||
| 648 | 669 | if(isset($attr['hideOriginals']) && $attr['hideOriginals'] === TRUE) |
| 649 | 670 | { |
| 650 | 671 | self::$hideOriginals = TRUE; |
| 651 | - } |
|
| 652 | - else |
|
| 672 | + } else |
|
| 653 | 673 | { |
| 654 | 674 | self::$hideOriginals = FALSE; |
| 655 | 675 | } |
@@ -661,15 +681,14 @@ discard block |
||
| 661 | 681 | //self::$middleware = $attr['middleware']; |
| 662 | 682 | if(is_array($attr['middleware']) && !empty($attr['middleware'])) |
| 663 | 683 | { |
| 664 | - foreach($attr['middleware'] as $middleware) |
|
| 665 | - self::$groupMiddleware[] = [ $attr['prefix'] => $middleware ]; |
|
| 666 | - } |
|
| 667 | - else |
|
| 684 | + foreach($attr['middleware'] as $middleware) { |
|
| 685 | + self::$groupMiddleware[] = [ $attr['prefix'] => $middleware ]; |
|
| 686 | + } |
|
| 687 | + } else |
|
| 668 | 688 | { |
| 669 | 689 | self::$groupMiddleware[] = [ $attr['prefix'] => $attr['middleware'] ]; |
| 670 | 690 | } |
| 671 | - } |
|
| 672 | - else |
|
| 691 | + } else |
|
| 673 | 692 | { |
| 674 | 693 | show_error('Group middleware not valid'); |
| 675 | 694 | } |
@@ -684,8 +703,10 @@ discard block |
||
| 684 | 703 | $controller = $uri[0]; |
| 685 | 704 | $method = isset($uri[1]) ? $uri[1] : NULL; |
| 686 | 705 | |
| 687 | - if(self::$hideOriginals === TRUE) |
|
| 688 | - self::$hiddenRoutes[] = [$controller => function(){ show_404(); }]; |
|
| 706 | + if(self::$hideOriginals === TRUE) { |
|
| 707 | + self::$hiddenRoutes[] = [$controller => function(){ show_404(); |
|
| 708 | + } |
|
| 709 | + }]; |
|
| 689 | 710 | |
| 690 | 711 | $route_attr['uses'] = $controller.( !is_null($method) ? '/'.$method : ''); |
| 691 | 712 | self::get('/', $route_attr); |
@@ -720,14 +741,17 @@ discard block |
||
| 720 | 741 | 'as' => $as |
| 721 | 742 | ]; |
| 722 | 743 | |
| 723 | - if(!is_null($attr) && !is_array($attr)) |
|
| 724 | - show_error('Default controller attributes must be an array',500,'Route error: bad attribute type'); |
|
| 744 | + if(!is_null($attr) && !is_array($attr)) { |
|
| 745 | + show_error('Default controller attributes must be an array',500,'Route error: bad attribute type'); |
|
| 746 | + } |
|
| 725 | 747 | |
| 726 | - if(!is_null($attr)) |
|
| 727 | - $routeAttr = array_merge($routeAttr,$attr); |
|
| 748 | + if(!is_null($attr)) { |
|
| 749 | + $routeAttr = array_merge($routeAttr,$attr); |
|
| 750 | + } |
|
| 728 | 751 | |
| 729 | - if(isset($attr['prefix'])) |
|
| 730 | - show_error('Default controller may not have a prefix!',500,'Route error: prefix not allowed'); |
|
| 752 | + if(isset($attr['prefix'])) { |
|
| 753 | + show_error('Default controller may not have a prefix!',500,'Route error: prefix not allowed'); |
|
| 754 | + } |
|
| 731 | 755 | |
| 732 | 756 | self::$defaultController = self::$routes[] = self::add('GET', '/', ['uses' => $controller, 'as' => $as],TRUE, TRUE); |
| 733 | 757 | } |
@@ -817,8 +841,9 @@ discard block |
||
| 817 | 841 | { |
| 818 | 842 | foreach(self::$routes as $route) |
| 819 | 843 | { |
| 820 | - if($route->name == $search) |
|
| 821 | - return base_url(self::compileRoute($route)->path); |
|
| 844 | + if($route->name == $search) { |
|
| 845 | + return base_url(self::compileRoute($route)->path); |
|
| 846 | + } |
|
| 822 | 847 | } |
| 823 | 848 | |
| 824 | 849 | show_error('The route "'.$search.'" is not defined', 500, 'Route error'); |
@@ -841,14 +866,17 @@ discard block |
||
| 841 | 866 | $routes[$route->verb][] = $route; |
| 842 | 867 | } |
| 843 | 868 | |
| 844 | - if(empty($routes)) |
|
| 845 | - return FALSE; |
|
| 869 | + if(empty($routes)) { |
|
| 870 | + return FALSE; |
|
| 871 | + } |
|
| 846 | 872 | |
| 847 | - if(is_null($requestMethod)) |
|
| 848 | - $requestMethod = $_SERVER['REQUEST_METHOD']; |
|
| 873 | + if(is_null($requestMethod)) { |
|
| 874 | + $requestMethod = $_SERVER['REQUEST_METHOD']; |
|
| 875 | + } |
|
| 849 | 876 | |
| 850 | - if(!isset($routes[$requestMethod])) |
|
| 851 | - return FALSE; |
|
| 877 | + if(!isset($routes[$requestMethod])) { |
|
| 878 | + return FALSE; |
|
| 879 | + } |
|
| 852 | 880 | |
| 853 | 881 | $routes = $routes[$requestMethod]; |
| 854 | 882 | |
@@ -868,8 +896,9 @@ discard block |
||
| 868 | 896 | { |
| 869 | 897 | $compiled = $route->compiled; |
| 870 | 898 | |
| 871 | - if($findPath == key($compiled)) |
|
| 872 | - return $route; |
|
| 899 | + if($findPath == key($compiled)) { |
|
| 900 | + return $route; |
|
| 901 | + } |
|
| 873 | 902 | } |
| 874 | 903 | } |
| 875 | 904 | |
@@ -65,20 +65,22 @@ discard block |
||
| 65 | 65 | |
| 66 | 66 | // FIXME: Solve ambiguity here! POST with _method="GET" makes no sense |
| 67 | 67 | |
| 68 | - if(isset($_POST['_method']) && in_array(strtoupper($_POST['_method']), $validMethods , TRUE)) |
|
| 69 | - $formMethod = strtoupper($_POST['_method']); |
|
| 68 | + if(isset($_POST['_method']) && in_array(strtoupper($_POST['_method']), $validMethods , TRUE)) { |
|
| 69 | + $formMethod = strtoupper($_POST['_method']); |
|
| 70 | + } |
|
| 70 | 71 | |
| 71 | 72 | if(is_null($formMethod)) |
| 72 | 73 | { |
| 73 | 74 | $this->requestMethod = $requestMethod; |
| 74 | - } |
|
| 75 | - else |
|
| 75 | + } else |
|
| 76 | 76 | { |
| 77 | - if($requestMethod == 'POST') |
|
| 78 | - $this->requestMethod = $formMethod; |
|
| 77 | + if($requestMethod == 'POST') { |
|
| 78 | + $this->requestMethod = $formMethod; |
|
| 79 | + } |
|
| 79 | 80 | |
| 80 | - if(!$this->CI->input->is_ajax_request() && $this->requestMethod == 'HEAD') |
|
| 81 | - $this->requestMethod = 'POST'; |
|
| 81 | + if(!$this->CI->input->is_ajax_request() && $this->requestMethod == 'HEAD') { |
|
| 82 | + $this->requestMethod = 'POST'; |
|
| 83 | + } |
|
| 82 | 84 | } |
| 83 | 85 | } |
| 84 | 86 | |
@@ -96,8 +98,7 @@ discard block |
||
| 96 | 98 | if(ENVIRONMENT != 'production') |
| 97 | 99 | { |
| 98 | 100 | show_error('The request method '.$this->requestMethod.' is not allowed to view the resource', 403, 'Forbidden method'); |
| 99 | - } |
|
| 100 | - else |
|
| 101 | + } else |
|
| 101 | 102 | { |
| 102 | 103 | show_404(); |
| 103 | 104 | } |
@@ -111,14 +112,12 @@ discard block |
||
| 111 | 112 | |
| 112 | 113 | $this->CI->output->_display(); |
| 113 | 114 | exit(0); |
| 114 | - } |
|
| 115 | - else |
|
| 115 | + } else |
|
| 116 | 116 | { |
| 117 | 117 | if(ENVIRONMENT != 'production') |
| 118 | 118 | { |
| 119 | 119 | show_error('The method '.$this->route->controller.'::'.$this->route->method.'() does not exists', 500, 'Method not found'); |
| 120 | - } |
|
| 121 | - else |
|
| 120 | + } else |
|
| 122 | 121 | { |
| 123 | 122 | show_404(); |
| 124 | 123 | } |
@@ -98,8 +98,9 @@ discard block |
||
| 98 | 98 | { |
| 99 | 99 | foreach($currentRoute->middleware as $middleware) |
| 100 | 100 | { |
| 101 | - if(!in_array($middleware,$_run)) |
|
| 102 | - $_run[] = $middleware; |
|
| 101 | + if(!in_array($middleware,$_run)) { |
|
| 102 | + $_run[] = $middleware; |
|
| 103 | + } |
|
| 103 | 104 | } |
| 104 | 105 | } |
| 105 | 106 | |
@@ -115,8 +116,9 @@ discard block |
||
| 115 | 116 | |
| 116 | 117 | if( $search === $path ) |
| 117 | 118 | { |
| 118 | - if(!in_array($middleware,$_run)) |
|
| 119 | - $_run[] = $middleware; |
|
| 119 | + if(!in_array($middleware,$_run)) { |
|
| 120 | + $_run[] = $middleware; |
|
| 121 | + } |
|
| 120 | 122 | } |
| 121 | 123 | } |
| 122 | 124 | } |
@@ -145,31 +147,36 @@ discard block |
||
| 145 | 147 | |
| 146 | 148 | $middlewareName = ucfirst($middlewareName).'_middleware'; |
| 147 | 149 | |
| 148 | - if(!file_exists($middlewareDir)) |
|
| 149 | - show_error('Unable to find (or read) the middleware folder: "'.$middlewareDir.'"'); |
|
| 150 | + if(!file_exists($middlewareDir)) { |
|
| 151 | + show_error('Unable to find (or read) the middleware folder: "'.$middlewareDir.'"'); |
|
| 152 | + } |
|
| 150 | 153 | |
| 151 | 154 | $runMiddleware = $middlewareDir.$middlewareName.'.php'; |
| 152 | 155 | |
| 153 | - if(!file_exists($runMiddleware)) |
|
| 154 | - show_error('Unable to find (or read) the middleware "'.$runMiddleware.'"'); |
|
| 156 | + if(!file_exists($runMiddleware)) { |
|
| 157 | + show_error('Unable to find (or read) the middleware "'.$runMiddleware.'"'); |
|
| 158 | + } |
|
| 155 | 159 | |
| 156 | 160 | require $runMiddleware; |
| 157 | 161 | |
| 158 | - if(!class_exists($middlewareName)) |
|
| 159 | - show_error('Class "'.$middlewareName.'" not found'); |
|
| 162 | + if(!class_exists($middlewareName)) { |
|
| 163 | + show_error('Class "'.$middlewareName.'" not found'); |
|
| 164 | + } |
|
| 160 | 165 | |
| 161 | 166 | $middleware = new $middlewareName(); |
| 162 | 167 | |
| 163 | 168 | // Call the current controller __beforeMiddleware() method, if exists: |
| 164 | - if(method_exists(self::$instance, '_beforeMiddleware')) |
|
| 165 | - self::$instance->_beforeMiddleware(); |
|
| 169 | + if(method_exists(self::$instance, '_beforeMiddleware')) { |
|
| 170 | + self::$instance->_beforeMiddleware(); |
|
| 171 | + } |
|
| 166 | 172 | |
| 167 | 173 | // Run the middleware |
| 168 | 174 | $middleware->run(); |
| 169 | 175 | |
| 170 | 176 | // Call the current controller _afterMiddleware() method, if exists: |
| 171 | - if(method_exists(self::$instance, '_afterMiddleware')) |
|
| 172 | - self::$instance->_afterMiddleware(); |
|
| 177 | + if(method_exists(self::$instance, '_afterMiddleware')) { |
|
| 178 | + self::$instance->_afterMiddleware(); |
|
| 179 | + } |
|
| 173 | 180 | |
| 174 | 181 | } |
| 175 | 182 | } |