@@ -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 | } |
@@ -811,7 +811,7 @@ discard block |
||
| 811 | 811 | array_pop(self::$hideOriginals); |
| 812 | 812 | |
| 813 | 813 | // Flushing nested middleware: |
| 814 | - for($i = 0; $i < $mcount; $i++) |
|
| 814 | + for ($i = 0; $i < $mcount; $i++) |
|
| 815 | 815 | array_pop(self::$middleware); |
| 816 | 816 | } |
| 817 | 817 | |
@@ -1031,7 +1031,7 @@ discard block |
||
| 1031 | 1031 | { |
| 1032 | 1032 | for ($i = 0; $i < $c_e_findPath; $i++) |
| 1033 | 1033 | { |
| 1034 | - if(in_array($i, $skip_seg)) |
|
| 1034 | + if (in_array($i, $skip_seg)) |
|
| 1035 | 1035 | continue; |
| 1036 | 1036 | |
| 1037 | 1037 | 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 | } |
@@ -811,8 +830,9 @@ discard block |
||
| 811 | 830 | array_pop(self::$hideOriginals); |
| 812 | 831 | |
| 813 | 832 | // Flushing nested middleware: |
| 814 | - for($i = 0; $i < $mcount; $i++) |
|
| 815 | - array_pop(self::$middleware); |
|
| 833 | + for($i = 0; $i < $mcount; $i++) { |
|
| 834 | + array_pop(self::$middleware); |
|
| 835 | + } |
|
| 816 | 836 | } |
| 817 | 837 | |
| 818 | 838 | |
@@ -833,14 +853,17 @@ discard block |
||
| 833 | 853 | 'as' => $as |
| 834 | 854 | ]; |
| 835 | 855 | |
| 836 | - if (!is_null($attr) && !is_array($attr)) |
|
| 837 | - show_error('Default controller attributes must be an array', 500, 'Route error: bad attribute type'); |
|
| 856 | + if (!is_null($attr) && !is_array($attr)) { |
|
| 857 | + show_error('Default controller attributes must be an array', 500, 'Route error: bad attribute type'); |
|
| 858 | + } |
|
| 838 | 859 | |
| 839 | - if (!is_null($attr)) |
|
| 840 | - $routeAttr = array_merge($routeAttr, $attr); |
|
| 860 | + if (!is_null($attr)) { |
|
| 861 | + $routeAttr = array_merge($routeAttr, $attr); |
|
| 862 | + } |
|
| 841 | 863 | |
| 842 | - if (isset($attr['prefix'])) |
|
| 843 | - show_error('Default controller may not have a prefix!', 500, 'Route error: prefix not allowed'); |
|
| 864 | + if (isset($attr['prefix'])) { |
|
| 865 | + show_error('Default controller may not have a prefix!', 500, 'Route error: prefix not allowed'); |
|
| 866 | + } |
|
| 844 | 867 | |
| 845 | 868 | self::$defaultController = self::$routes[] = self::add('GET', '/', ['uses' => $controller, 'as' => $as], TRUE, TRUE); |
| 846 | 869 | } |
@@ -859,14 +882,14 @@ discard block |
||
| 859 | 882 | if (is_null($verb)) |
| 860 | 883 | { |
| 861 | 884 | return self::$routes; |
| 862 | - } |
|
| 863 | - else |
|
| 885 | + } else |
|
| 864 | 886 | { |
| 865 | 887 | $routes = []; |
| 866 | 888 | foreach (self::$routes as $route) |
| 867 | 889 | { |
| 868 | - if ($route->verb == $verb) |
|
| 869 | - $routes[] = $route; |
|
| 890 | + if ($route->verb == $verb) { |
|
| 891 | + $routes[] = $route; |
|
| 892 | + } |
|
| 870 | 893 | } |
| 871 | 894 | return $routes; |
| 872 | 895 | } |
@@ -963,18 +986,21 @@ discard block |
||
| 963 | 986 | */ |
| 964 | 987 | public static function getRouteByPath($path, $requestMethod = NULL) |
| 965 | 988 | { |
| 966 | - if (is_null($requestMethod)) |
|
| 967 | - $requestMethod = $_SERVER['REQUEST_METHOD']; |
|
| 989 | + if (is_null($requestMethod)) { |
|
| 990 | + $requestMethod = $_SERVER['REQUEST_METHOD']; |
|
| 991 | + } |
|
| 968 | 992 | |
| 969 | 993 | $routes = self::getRoutes($requestMethod); |
| 970 | 994 | |
| 971 | - if (empty($routes)) |
|
| 972 | - return FALSE; |
|
| 995 | + if (empty($routes)) { |
|
| 996 | + return FALSE; |
|
| 997 | + } |
|
| 973 | 998 | |
| 974 | 999 | $path = trim($path); |
| 975 | 1000 | |
| 976 | - if ($path == '') |
|
| 977 | - return self::$defaultController; |
|
| 1001 | + if ($path == '') { |
|
| 1002 | + return self::$defaultController; |
|
| 1003 | + } |
|
| 978 | 1004 | |
| 979 | 1005 | $wildcards = |
| 980 | 1006 | [ |
@@ -1000,10 +1026,10 @@ discard block |
||
| 1000 | 1026 | |
| 1001 | 1027 | if ($mode == 'exact') |
| 1002 | 1028 | { |
| 1003 | - if ($findPath == $compiledPath) |
|
| 1004 | - return $route; |
|
| 1005 | - } |
|
| 1006 | - else |
|
| 1029 | + if ($findPath == $compiledPath) { |
|
| 1030 | + return $route; |
|
| 1031 | + } |
|
| 1032 | + } else |
|
| 1007 | 1033 | { |
| 1008 | 1034 | $e_findPath = explode('/', $findPath); |
| 1009 | 1035 | $e_compiledPath = explode('/', $compiledPath); |
@@ -1023,24 +1049,28 @@ discard block |
||
| 1023 | 1049 | |
| 1024 | 1050 | $valid = (bool) preg_match('#^'.$reg.'$#', $e_findPath[$i]); |
| 1025 | 1051 | |
| 1026 | - if ($valid && $count > 0) |
|
| 1027 | - $skip_seg[] = $i; |
|
| 1052 | + if ($valid && $count > 0) { |
|
| 1053 | + $skip_seg[] = $i; |
|
| 1054 | + } |
|
| 1028 | 1055 | } |
| 1029 | 1056 | |
| 1030 | 1057 | if ($valid) |
| 1031 | 1058 | { |
| 1032 | 1059 | for ($i = 0; $i < $c_e_findPath; $i++) |
| 1033 | 1060 | { |
| 1034 | - if(in_array($i, $skip_seg)) |
|
| 1035 | - continue; |
|
| 1061 | + if(in_array($i, $skip_seg)) { |
|
| 1062 | + continue; |
|
| 1063 | + } |
|
| 1036 | 1064 | |
| 1037 | - if ($valid) |
|
| 1038 | - $valid = $e_findPath[$i] == $e_compiledPath[$i]; |
|
| 1065 | + if ($valid) { |
|
| 1066 | + $valid = $e_findPath[$i] == $e_compiledPath[$i]; |
|
| 1067 | + } |
|
| 1039 | 1068 | } |
| 1040 | 1069 | } |
| 1041 | 1070 | |
| 1042 | - if ($valid) |
|
| 1043 | - return $route; |
|
| 1071 | + if ($valid) { |
|
| 1072 | + return $route; |
|
| 1073 | + } |
|
| 1044 | 1074 | } |
| 1045 | 1075 | } |
| 1046 | 1076 | } |
@@ -1074,8 +1104,9 @@ discard block |
||
| 1074 | 1104 | |
| 1075 | 1105 | for ($s = 0; $s < count($r_seg); $s++) |
| 1076 | 1106 | { |
| 1077 | - if (!isset($p_seg[$s])) |
|
| 1078 | - continue; |
|
| 1107 | + if (!isset($p_seg[$s])) { |
|
| 1108 | + continue; |
|
| 1109 | + } |
|
| 1079 | 1110 | |
| 1080 | 1111 | if ($r_seg[$s] != $p_seg[$s]) |
| 1081 | 1112 | { |