@@ -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 | } |
@@ -570,12 +570,12 @@ discard block |
||
570 | 570 | |
571 | 571 | foreach ($replaces as $regex => $replace) |
572 | 572 | { |
573 | - if($customRegex) |
|
573 | + if ($customRegex) |
|
574 | 574 | continue; |
575 | 575 | |
576 | 576 | $matches = []; |
577 | 577 | |
578 | - if(preg_match('/^\{(.*)\}$/', $segment)) |
|
578 | + if (preg_match('/^\{(.*)\}$/', $segment)) |
|
579 | 579 | { |
580 | 580 | $foundedArgs[$key] = $segment; |
581 | 581 | } |
@@ -583,7 +583,7 @@ discard block |
||
583 | 583 | $c = 0; |
584 | 584 | $segment = preg_replace('/'.$regex.'/', $replace, $segment, 1, $c); |
585 | 585 | |
586 | - if( $regex == array_keys($replaces)[0] && $c > 0) |
|
586 | + if ($regex == array_keys($replaces)[0] && $c > 0) |
|
587 | 587 | $customRegex = TRUE; |
588 | 588 | } |
589 | 589 | } |
@@ -809,11 +809,11 @@ discard block |
||
809 | 809 | array_pop(self::$prefix); |
810 | 810 | array_pop(self::$hideOriginals); |
811 | 811 | |
812 | - if( isset($attr['namespace']) ) |
|
812 | + if (isset($attr['namespace'])) |
|
813 | 813 | array_pop(self::$namespace); |
814 | 814 | |
815 | 815 | // Flushing nested middleware: |
816 | - for($i = 0; $i < $mcount; $i++) |
|
816 | + for ($i = 0; $i < $mcount; $i++) |
|
817 | 817 | array_pop(self::$middleware); |
818 | 818 | } |
819 | 819 | |
@@ -1033,7 +1033,7 @@ discard block |
||
1033 | 1033 | { |
1034 | 1034 | for ($i = 0; $i < $c_e_findPath; $i++) |
1035 | 1035 | { |
1036 | - if(in_array($i, $skip_seg)) |
|
1036 | + if (in_array($i, $skip_seg)) |
|
1037 | 1037 | continue; |
1038 | 1038 | |
1039 | 1039 | if ($valid) |
@@ -146,11 +146,13 @@ discard block |
||
146 | 146 | $controller = $parsedController[1]; |
147 | 147 | $method = $parsedController[2]; |
148 | 148 | |
149 | - if (!is_string($path)) |
|
150 | - show_error('Route path must be a string ', 500, 'Route error: bad route path'); |
|
149 | + if (!is_string($path)) { |
|
150 | + show_error('Route path must be a string ', 500, 'Route error: bad route path'); |
|
151 | + } |
|
151 | 152 | |
152 | - if (!is_string($verb)) |
|
153 | - show_error('Route HTTP Verb must be a string', 500, 'Route error: bad verb type'); |
|
153 | + if (!is_string($verb)) { |
|
154 | + show_error('Route HTTP Verb must be a string', 500, 'Route error: bad verb type'); |
|
155 | + } |
|
154 | 156 | |
155 | 157 | $verb = strtoupper($verb); |
156 | 158 | |
@@ -186,30 +188,36 @@ discard block |
||
186 | 188 | $route['prefix'] = NULL; |
187 | 189 | $group_prefix = implode('/', self::$prefix); |
188 | 190 | |
189 | - if ($group_prefix) |
|
190 | - $route['prefix'] = $group_prefix.'/'; |
|
191 | + if ($group_prefix) { |
|
192 | + $route['prefix'] = $group_prefix.'/'; |
|
193 | + } |
|
191 | 194 | |
192 | - if (isset($attr['prefix'])) |
|
193 | - $route['prefix'] .= $attr['prefix']; |
|
195 | + if (isset($attr['prefix'])) { |
|
196 | + $route['prefix'] .= $attr['prefix']; |
|
197 | + } |
|
194 | 198 | |
195 | 199 | // Setting up the namespace |
196 | 200 | |
197 | 201 | $route['namespace'] = NULL; |
198 | 202 | $group_namespace = implode('/', self::$namespace); |
199 | 203 | |
200 | - if (!is_null($group_namespace)) |
|
201 | - $route['namespace'] = $group_namespace.'/'; |
|
202 | - if (isset($attr['namespace'])) |
|
203 | - $route['namespace'] .= $attr['namespace']; |
|
204 | + if (!is_null($group_namespace)) { |
|
205 | + $route['namespace'] = $group_namespace.'/'; |
|
206 | + } |
|
207 | + if (isset($attr['namespace'])) { |
|
208 | + $route['namespace'] .= $attr['namespace']; |
|
209 | + } |
|
204 | 210 | |
205 | 211 | $route['prefix'] = trim($route['prefix'], '/'); |
206 | 212 | $route['namespace'] = trim($route['namespace'], '/'); |
207 | 213 | |
208 | - if (empty($route['prefix'])) |
|
209 | - $route['prefix'] = NULL; |
|
214 | + if (empty($route['prefix'])) { |
|
215 | + $route['prefix'] = NULL; |
|
216 | + } |
|
210 | 217 | |
211 | - if (empty($route['namespace'])) |
|
212 | - $route['namespace'] = NULL; |
|
218 | + if (empty($route['namespace'])) { |
|
219 | + $route['namespace'] = NULL; |
|
220 | + } |
|
213 | 221 | |
214 | 222 | // Route middleware |
215 | 223 | $route['middleware'] = []; |
@@ -219,14 +227,14 @@ discard block |
||
219 | 227 | { |
220 | 228 | if (is_array($attr['middleware'])) |
221 | 229 | { |
222 | - foreach ($attr['middleware'] as $middleware) |
|
223 | - $route['middleware'][] = $middleware; # Group |
|
224 | - } |
|
225 | - elseif (is_string($attr['middleware'])) |
|
230 | + foreach ($attr['middleware'] as $middleware) { |
|
231 | + $route['middleware'][] = $middleware; |
|
232 | + } |
|
233 | + # Group |
|
234 | + } elseif (is_string($attr['middleware'])) |
|
226 | 235 | { |
227 | 236 | $route['middleware'][] = $attr['middleware']; # Group |
228 | - } |
|
229 | - else |
|
237 | + } else |
|
230 | 238 | { |
231 | 239 | show_error('Route middleware must be a string or an array', 500, 'Route error: bad middleware format'); |
232 | 240 | } |
@@ -398,8 +406,9 @@ discard block |
||
398 | 406 | */ |
399 | 407 | public static function matches($verbs, $url, $attr, $hideOriginal = FALSE) |
400 | 408 | { |
401 | - if (!is_array($verbs)) |
|
402 | - show_error('Route::matches() first argument must be an array of valid HTTP Verbs', 500, 'Route error: bad Route::matches() verb list'); |
|
409 | + if (!is_array($verbs)) { |
|
410 | + show_error('Route::matches() first argument must be an array of valid HTTP Verbs', 500, 'Route error: bad Route::matches() verb list'); |
|
411 | + } |
|
403 | 412 | |
404 | 413 | foreach ($verbs as $verb) |
405 | 414 | { |
@@ -427,19 +436,23 @@ discard block |
||
427 | 436 | |
428 | 437 | $hideOriginal = FALSE; |
429 | 438 | |
430 | - if (isset($attr['namespace'])) |
|
431 | - $base_attr['namespace'] = $attr['namespace']; |
|
439 | + if (isset($attr['namespace'])) { |
|
440 | + $base_attr['namespace'] = $attr['namespace']; |
|
441 | + } |
|
432 | 442 | |
433 | - if (isset($attr['middleware'])) |
|
434 | - $base_attr['middleware'] = $attr['middleware']; |
|
443 | + if (isset($attr['middleware'])) { |
|
444 | + $base_attr['middleware'] = $attr['middleware']; |
|
445 | + } |
|
435 | 446 | |
436 | - if (isset($attr['hideOriginal'])) |
|
437 | - $hideOriginal = (bool) $attr['hideOriginal']; |
|
447 | + if (isset($attr['hideOriginal'])) { |
|
448 | + $hideOriginal = (bool) $attr['hideOriginal']; |
|
449 | + } |
|
438 | 450 | |
439 | 451 | $base_attr['prefix'] = strtolower($name); |
440 | 452 | |
441 | - if (isset($attr['prefix'])) |
|
442 | - $base_attr['prefix'] = $attr['prefix']; |
|
453 | + if (isset($attr['prefix'])) { |
|
454 | + $base_attr['prefix'] = $attr['prefix']; |
|
455 | + } |
|
443 | 456 | |
444 | 457 | $only = []; |
445 | 458 | |
@@ -450,8 +463,7 @@ discard block |
||
450 | 463 | if (is_array($attr['only'])) |
451 | 464 | { |
452 | 465 | $only = $attr['only']; |
453 | - } |
|
454 | - else |
|
466 | + } else |
|
455 | 467 | { |
456 | 468 | $only[] = $attr['only']; |
457 | 469 | } |
@@ -528,13 +540,15 @@ discard block |
||
528 | 540 | |
529 | 541 | $path = $route->path; |
530 | 542 | |
531 | - if (!is_null($prefix)) |
|
532 | - $path = $prefix.'/'.$path; |
|
543 | + if (!is_null($prefix)) { |
|
544 | + $path = $prefix.'/'.$path; |
|
545 | + } |
|
533 | 546 | |
534 | 547 | $controller = $route->controller.'/'.$route->method; |
535 | 548 | |
536 | - if (!is_null($namespace)) |
|
537 | - $controller = $namespace.'/'.$controller; |
|
549 | + if (!is_null($namespace)) { |
|
550 | + $controller = $namespace.'/'.$controller; |
|
551 | + } |
|
538 | 552 | |
539 | 553 | $path = trim($path, '/'); |
540 | 554 | $controller = trim($controller, '/'); |
@@ -570,8 +584,9 @@ discard block |
||
570 | 584 | |
571 | 585 | foreach ($replaces as $regex => $replace) |
572 | 586 | { |
573 | - if($customRegex) |
|
574 | - continue; |
|
587 | + if($customRegex) { |
|
588 | + continue; |
|
589 | + } |
|
575 | 590 | |
576 | 591 | $matches = []; |
577 | 592 | |
@@ -583,8 +598,9 @@ discard block |
||
583 | 598 | $c = 0; |
584 | 599 | $segment = preg_replace('/'.$regex.'/', $replace, $segment, 1, $c); |
585 | 600 | |
586 | - if( $regex == array_keys($replaces)[0] && $c > 0) |
|
587 | - $customRegex = TRUE; |
|
601 | + if( $regex == array_keys($replaces)[0] && $c > 0) { |
|
602 | + $customRegex = TRUE; |
|
603 | + } |
|
588 | 604 | } |
589 | 605 | } |
590 | 606 | |
@@ -602,11 +618,11 @@ discard block |
||
602 | 618 | { |
603 | 619 | $args['optional'][] = $arg; |
604 | 620 | $argConstraint = TRUE; |
605 | - } |
|
606 | - else |
|
621 | + } else |
|
607 | 622 | { |
608 | - if ($argConstraint) |
|
609 | - show_error('Optional route path argument not valid at this position', 500, 'Route error'); |
|
623 | + if ($argConstraint) { |
|
624 | + show_error('Optional route path argument not valid at this position', 500, 'Route error'); |
|
625 | + } |
|
610 | 626 | $args['required'][] = $arg; |
611 | 627 | } |
612 | 628 | } |
@@ -721,12 +737,14 @@ discard block |
||
721 | 737 | $path = key($route); |
722 | 738 | $_404 = $route[$path]; |
723 | 739 | |
724 | - if (!isset($routes[$path])) |
|
725 | - $routes[$path] = $_404; |
|
740 | + if (!isset($routes[$path])) { |
|
741 | + $routes[$path] = $_404; |
|
742 | + } |
|
726 | 743 | } |
727 | 744 | |
728 | - if (is_null(self::$defaultController)) |
|
729 | - show_error('You must specify a home route: Route::home() as default controller!', 500, 'Route error: missing default controller'); |
|
745 | + if (is_null(self::$defaultController)) { |
|
746 | + show_error('You must specify a home route: Route::home() as default controller!', 500, 'Route error: missing default controller'); |
|
747 | + } |
|
730 | 748 | |
731 | 749 | $defaultController = self::$defaultController->compiled; |
732 | 750 | $defaultController = $defaultController[key($defaultController)]; |
@@ -760,11 +778,13 @@ discard block |
||
760 | 778 | */ |
761 | 779 | public static function group($attr, $routes) |
762 | 780 | { |
763 | - if (!is_array($attr)) |
|
764 | - show_error('Group attribute must be a valid array'); |
|
781 | + if (!is_array($attr)) { |
|
782 | + show_error('Group attribute must be a valid array'); |
|
783 | + } |
|
765 | 784 | |
766 | - if (!isset($attr['prefix'])) |
|
767 | - show_error('You must specify an prefix!'); |
|
785 | + if (!isset($attr['prefix'])) { |
|
786 | + show_error('You must specify an prefix!'); |
|
787 | + } |
|
768 | 788 | |
769 | 789 | self::$prefix[] = $attr['prefix']; |
770 | 790 | |
@@ -789,16 +809,15 @@ discard block |
||
789 | 809 | if (is_array($attr['middleware']) && !empty($attr['middleware'])) |
790 | 810 | { |
791 | 811 | $mcount = count($attr['middleware']); |
792 | - foreach ($attr['middleware'] as $middleware) |
|
793 | - self::$middleware[] = $middleware; |
|
794 | - } |
|
795 | - else |
|
812 | + foreach ($attr['middleware'] as $middleware) { |
|
813 | + self::$middleware[] = $middleware; |
|
814 | + } |
|
815 | + } else |
|
796 | 816 | { |
797 | 817 | self::$middleware[] = $attr['middleware']; |
798 | 818 | $mcount = 1; |
799 | 819 | } |
800 | - } |
|
801 | - else |
|
820 | + } else |
|
802 | 821 | { |
803 | 822 | show_error('Group middleware must be an array o a string', 500, 'Route error'); |
804 | 823 | } |
@@ -809,12 +828,14 @@ discard block |
||
809 | 828 | array_pop(self::$prefix); |
810 | 829 | array_pop(self::$hideOriginals); |
811 | 830 | |
812 | - if( isset($attr['namespace']) ) |
|
813 | - array_pop(self::$namespace); |
|
831 | + if( isset($attr['namespace']) ) { |
|
832 | + array_pop(self::$namespace); |
|
833 | + } |
|
814 | 834 | |
815 | 835 | // Flushing nested middleware: |
816 | - for($i = 0; $i < $mcount; $i++) |
|
817 | - array_pop(self::$middleware); |
|
836 | + for($i = 0; $i < $mcount; $i++) { |
|
837 | + array_pop(self::$middleware); |
|
838 | + } |
|
818 | 839 | } |
819 | 840 | |
820 | 841 | |
@@ -835,14 +856,17 @@ discard block |
||
835 | 856 | 'as' => $as |
836 | 857 | ]; |
837 | 858 | |
838 | - if (!is_null($attr) && !is_array($attr)) |
|
839 | - show_error('Default controller attributes must be an array', 500, 'Route error: bad attribute type'); |
|
859 | + if (!is_null($attr) && !is_array($attr)) { |
|
860 | + show_error('Default controller attributes must be an array', 500, 'Route error: bad attribute type'); |
|
861 | + } |
|
840 | 862 | |
841 | - if (!is_null($attr)) |
|
842 | - $routeAttr = array_merge($routeAttr, $attr); |
|
863 | + if (!is_null($attr)) { |
|
864 | + $routeAttr = array_merge($routeAttr, $attr); |
|
865 | + } |
|
843 | 866 | |
844 | - if (isset($attr['prefix'])) |
|
845 | - show_error('Default controller may not have a prefix!', 500, 'Route error: prefix not allowed'); |
|
867 | + if (isset($attr['prefix'])) { |
|
868 | + show_error('Default controller may not have a prefix!', 500, 'Route error: prefix not allowed'); |
|
869 | + } |
|
846 | 870 | |
847 | 871 | self::$defaultController = self::$routes[] = self::add('GET', '/', ['uses' => $controller, 'as' => $as], TRUE, TRUE); |
848 | 872 | } |
@@ -861,14 +885,14 @@ discard block |
||
861 | 885 | if (is_null($verb)) |
862 | 886 | { |
863 | 887 | return self::$routes; |
864 | - } |
|
865 | - else |
|
888 | + } else |
|
866 | 889 | { |
867 | 890 | $routes = []; |
868 | 891 | foreach (self::$routes as $route) |
869 | 892 | { |
870 | - if ($route->verb == $verb) |
|
871 | - $routes[] = $route; |
|
893 | + if ($route->verb == $verb) { |
|
894 | + $routes[] = $route; |
|
895 | + } |
|
872 | 896 | } |
873 | 897 | return $routes; |
874 | 898 | } |
@@ -965,18 +989,21 @@ discard block |
||
965 | 989 | */ |
966 | 990 | public static function getRouteByPath($path, $requestMethod = NULL) |
967 | 991 | { |
968 | - if (is_null($requestMethod)) |
|
969 | - $requestMethod = $_SERVER['REQUEST_METHOD']; |
|
992 | + if (is_null($requestMethod)) { |
|
993 | + $requestMethod = $_SERVER['REQUEST_METHOD']; |
|
994 | + } |
|
970 | 995 | |
971 | 996 | $routes = self::getRoutes($requestMethod); |
972 | 997 | |
973 | - if (empty($routes)) |
|
974 | - return FALSE; |
|
998 | + if (empty($routes)) { |
|
999 | + return FALSE; |
|
1000 | + } |
|
975 | 1001 | |
976 | 1002 | $path = trim($path); |
977 | 1003 | |
978 | - if ($path == '') |
|
979 | - return self::$defaultController; |
|
1004 | + if ($path == '') { |
|
1005 | + return self::$defaultController; |
|
1006 | + } |
|
980 | 1007 | |
981 | 1008 | $wildcards = |
982 | 1009 | [ |
@@ -1002,10 +1029,10 @@ discard block |
||
1002 | 1029 | |
1003 | 1030 | if ($mode == 'exact') |
1004 | 1031 | { |
1005 | - if ($findPath == $compiledPath) |
|
1006 | - return $route; |
|
1007 | - } |
|
1008 | - else |
|
1032 | + if ($findPath == $compiledPath) { |
|
1033 | + return $route; |
|
1034 | + } |
|
1035 | + } else |
|
1009 | 1036 | { |
1010 | 1037 | $e_findPath = explode('/', $findPath); |
1011 | 1038 | $e_compiledPath = explode('/', $compiledPath); |
@@ -1025,24 +1052,28 @@ discard block |
||
1025 | 1052 | |
1026 | 1053 | $valid = (bool) preg_match('#^'.$reg.'$#', $e_findPath[$i]); |
1027 | 1054 | |
1028 | - if ($valid && $count > 0) |
|
1029 | - $skip_seg[] = $i; |
|
1055 | + if ($valid && $count > 0) { |
|
1056 | + $skip_seg[] = $i; |
|
1057 | + } |
|
1030 | 1058 | } |
1031 | 1059 | |
1032 | 1060 | if ($valid) |
1033 | 1061 | { |
1034 | 1062 | for ($i = 0; $i < $c_e_findPath; $i++) |
1035 | 1063 | { |
1036 | - if(in_array($i, $skip_seg)) |
|
1037 | - continue; |
|
1064 | + if(in_array($i, $skip_seg)) { |
|
1065 | + continue; |
|
1066 | + } |
|
1038 | 1067 | |
1039 | - if ($valid) |
|
1040 | - $valid = $e_findPath[$i] == $e_compiledPath[$i]; |
|
1068 | + if ($valid) { |
|
1069 | + $valid = $e_findPath[$i] == $e_compiledPath[$i]; |
|
1070 | + } |
|
1041 | 1071 | } |
1042 | 1072 | } |
1043 | 1073 | |
1044 | - if ($valid) |
|
1045 | - return $route; |
|
1074 | + if ($valid) { |
|
1075 | + return $route; |
|
1076 | + } |
|
1046 | 1077 | } |
1047 | 1078 | } |
1048 | 1079 | } |
@@ -1076,8 +1107,9 @@ discard block |
||
1076 | 1107 | |
1077 | 1108 | for ($s = 0; $s < count($r_seg); $s++) |
1078 | 1109 | { |
1079 | - if (!isset($p_seg[$s])) |
|
1080 | - continue; |
|
1110 | + if (!isset($p_seg[$s])) { |
|
1111 | + continue; |
|
1112 | + } |
|
1081 | 1113 | |
1082 | 1114 | if ($r_seg[$s] != $p_seg[$s]) |
1083 | 1115 | { |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | if (ENVIRONMENT != 'production') |
96 | 96 | show_error('The request method '.$this->requestMethod.' is not allowed to view the resource', 403, 'Forbidden method'); |
97 | 97 | |
98 | - if(is_null(Route::get404())) |
|
98 | + if (is_null(Route::get404())) |
|
99 | 99 | show_404(); |
100 | 100 | |
101 | 101 | if (Route::get404()->controller != get_class($this->CI)) |
@@ -110,16 +110,16 @@ discard block |
||
110 | 110 | |
111 | 111 | // Redirect to 404 if not enough parameters provided |
112 | 112 | |
113 | - if(count($path_args) < count($route_args['required'])) |
|
113 | + if (count($path_args) < count($route_args['required'])) |
|
114 | 114 | redirect(Route::get404()->path); |
115 | 115 | |
116 | - if(count($path_args) == 0) |
|
116 | + if (count($path_args) == 0) |
|
117 | 117 | { |
118 | 118 | $this->CI->{$this->route->method}(); |
119 | 119 | } |
120 | 120 | else |
121 | 121 | { |
122 | - call_user_func_array( [$this->CI, $this->route->method], array_values($path_args) ); |
|
122 | + call_user_func_array([$this->CI, $this->route->method], array_values($path_args)); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | // TODO: Add support to hooks in this execution thread |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | if (ENVIRONMENT != 'production') |
133 | 133 | show_error('The method '.$this->route->controller.'::'.$this->route->method.'() does not exists', 500, 'Method not found'); |
134 | 134 | |
135 | - if(is_null(Route::get404())) |
|
135 | + if (is_null(Route::get404())) |
|
136 | 136 | show_404(); |
137 | 137 | |
138 | 138 | if (Route::get404()->controller != get_class($this->CI)) |
@@ -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 | |
@@ -92,16 +94,18 @@ discard block |
||
92 | 94 | { |
93 | 95 | if (!$this->route) |
94 | 96 | { |
95 | - if (ENVIRONMENT != 'production') |
|
96 | - show_error('The request method '.$this->requestMethod.' is not allowed to view the resource', 403, 'Forbidden method'); |
|
97 | + if (ENVIRONMENT != 'production') { |
|
98 | + show_error('The request method '.$this->requestMethod.' is not allowed to view the resource', 403, 'Forbidden method'); |
|
99 | + } |
|
97 | 100 | |
98 | - if(is_null(Route::get404())) |
|
99 | - show_404(); |
|
101 | + if(is_null(Route::get404())) { |
|
102 | + show_404(); |
|
103 | + } |
|
100 | 104 | |
101 | - if (Route::get404()->controller != get_class($this->CI)) |
|
102 | - Route::trigger404(); |
|
103 | - } |
|
104 | - else |
|
105 | + if (Route::get404()->controller != get_class($this->CI)) { |
|
106 | + Route::trigger404(); |
|
107 | + } |
|
108 | + } else |
|
105 | 109 | { |
106 | 110 | if (method_exists($this->CI, $this->route->method)) |
107 | 111 | { |
@@ -110,14 +114,14 @@ discard block |
||
110 | 114 | |
111 | 115 | // Redirect to 404 if not enough parameters provided |
112 | 116 | |
113 | - if(count($path_args) < count($route_args['required'])) |
|
114 | - redirect(Route::get404()->path); |
|
117 | + if(count($path_args) < count($route_args['required'])) { |
|
118 | + redirect(Route::get404()->path); |
|
119 | + } |
|
115 | 120 | |
116 | 121 | if(count($path_args) == 0) |
117 | 122 | { |
118 | 123 | $this->CI->{$this->route->method}(); |
119 | - } |
|
120 | - else |
|
124 | + } else |
|
121 | 125 | { |
122 | 126 | call_user_func_array( [$this->CI, $this->route->method], array_values($path_args) ); |
123 | 127 | } |
@@ -126,17 +130,19 @@ discard block |
||
126 | 130 | |
127 | 131 | $this->CI->output->_display(); |
128 | 132 | exit(0); |
129 | - } |
|
130 | - else |
|
133 | + } else |
|
131 | 134 | { |
132 | - if (ENVIRONMENT != 'production') |
|
133 | - show_error('The method '.$this->route->controller.'::'.$this->route->method.'() does not exists', 500, 'Method not found'); |
|
135 | + if (ENVIRONMENT != 'production') { |
|
136 | + show_error('The method '.$this->route->controller.'::'.$this->route->method.'() does not exists', 500, 'Method not found'); |
|
137 | + } |
|
134 | 138 | |
135 | - if(is_null(Route::get404())) |
|
136 | - show_404(); |
|
139 | + if(is_null(Route::get404())) { |
|
140 | + show_404(); |
|
141 | + } |
|
137 | 142 | |
138 | - if (Route::get404()->controller != get_class($this->CI)) |
|
139 | - Route::trigger404(); |
|
143 | + if (Route::get404()->controller != get_class($this->CI)) { |
|
144 | + Route::trigger404(); |
|
145 | + } |
|
140 | 146 | } |
141 | 147 | } |
142 | 148 | } |