@@ -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(); |
@@ -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 | { |
@@ -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 | } |