@@ -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 | } |
@@ -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,22 +94,21 @@ discard block |
||
| 92 | 94 | { |
| 93 | 95 | if(!$this->route) |
| 94 | 96 | { |
| 95 | - if(is_null(Route::get404())) |
|
| 96 | - show_404(); |
|
| 97 | + if(is_null(Route::get404())) { |
|
| 98 | + show_404(); |
|
| 99 | + } |
|
| 97 | 100 | |
| 98 | 101 | if(Route::get404()->controller != get_class($this->CI)) |
| 99 | 102 | { |
| 100 | 103 | if(ENVIRONMENT != 'production') |
| 101 | 104 | { |
| 102 | 105 | show_error('The request method '.$this->requestMethod.' is not allowed to view the resource', 403, 'Forbidden method'); |
| 103 | - } |
|
| 104 | - else |
|
| 106 | + } else |
|
| 105 | 107 | { |
| 106 | 108 | redirect(Route::get404()->path); |
| 107 | 109 | } |
| 108 | 110 | } |
| 109 | - } |
|
| 110 | - else |
|
| 111 | + } else |
|
| 111 | 112 | { |
| 112 | 113 | if(method_exists($this->CI,$this->route->method)) |
| 113 | 114 | { |
@@ -117,14 +118,12 @@ discard block |
||
| 117 | 118 | |
| 118 | 119 | $this->CI->output->_display(); |
| 119 | 120 | exit(0); |
| 120 | - } |
|
| 121 | - else |
|
| 121 | + } else |
|
| 122 | 122 | { |
| 123 | 123 | if(ENVIRONMENT != 'production') |
| 124 | 124 | { |
| 125 | 125 | show_error('The method '.$this->route->controller.'::'.$this->route->method.'() does not exists', 500, 'Method not found'); |
| 126 | - } |
|
| 127 | - else |
|
| 126 | + } else |
|
| 128 | 127 | { |
| 129 | 128 | redirect(Route::get404()->path); |
| 130 | 129 | } |
@@ -110,7 +110,6 @@ discard block |
||
| 110 | 110 | * Generic method to add a improved route |
| 111 | 111 | * |
| 112 | 112 | * @param mixed $verb String or array of string of valid HTTP Verbs that will be accepted in this route |
| 113 | - * @param mixed $url String or array of strings that will trigger this route |
|
| 114 | 113 | * @param array $attr Associative array of route attributes |
| 115 | 114 | * @param bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside |
| 116 | 115 | * |
@@ -267,7 +266,7 @@ discard block |
||
| 267 | 266 | /** |
| 268 | 267 | * Adds a GET route, alias of Route::add('GET',$url,$attr,$hideOriginal) |
| 269 | 268 | * |
| 270 | - * @param mixed $url String or array of strings that will trigger this route |
|
| 269 | + * @param string $url String or array of strings that will trigger this route |
|
| 271 | 270 | * @param array $attr Associative array of route attributes |
| 272 | 271 | * @param bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside |
| 273 | 272 | * |
@@ -284,7 +283,7 @@ discard block |
||
| 284 | 283 | /** |
| 285 | 284 | * Adds a POST route, alias of Route::add('POST',$url,$attr,$hideOriginal) |
| 286 | 285 | * |
| 287 | - * @param mixed $url String or array of strings that will trigger this route |
|
| 286 | + * @param string $url String or array of strings that will trigger this route |
|
| 288 | 287 | * @param array $attr Associative array of route attributes |
| 289 | 288 | * @param bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside |
| 290 | 289 | * |
@@ -335,7 +334,7 @@ discard block |
||
| 335 | 334 | /** |
| 336 | 335 | * Adds a DELETE route, alias of Route::add('DELETE',$url,$attr,$hideOriginal) |
| 337 | 336 | * |
| 338 | - * @param mixed $url String or array of strings that will trigger this route |
|
| 337 | + * @param string $url String or array of strings that will trigger this route |
|
| 339 | 338 | * @param array $attr Associative array of route attributes |
| 340 | 339 | * @param bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside |
| 341 | 340 | * |
@@ -373,8 +372,8 @@ discard block |
||
| 373 | 372 | /** |
| 374 | 373 | * Adds a list of routes with the verbs contained in $verbs, alias of Route::add($verbs,$url,$attr,$hideOriginal) |
| 375 | 374 | * |
| 376 | - * @param mixed $verb String or array of string of valid HTTP Verbs that will be accepted in this route |
|
| 377 | - * @param mixed $url String or array of strings that will trigger this route |
|
| 375 | + * @param string[] $verbs String or array of string of valid HTTP Verbs that will be accepted in this route |
|
| 376 | + * @param string $url String or array of strings that will trigger this route |
|
| 378 | 377 | * @param array $attr Associative array of route attributes |
| 379 | 378 | * @param bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside |
| 380 | 379 | * |
@@ -408,7 +407,6 @@ discard block |
||
| 408 | 407 | * |
| 409 | 408 | * PLEASE NOTE: This is NOT a crud generator, just a bundle of predefined routes. |
| 410 | 409 | * |
| 411 | - * @param string $url String or array of strings that will trigger this route |
|
| 412 | 410 | * @param string $controller Controller name (only controller name) |
| 413 | 411 | * @param array $attr Associative array of route attributes |
| 414 | 412 | * |
@@ -716,10 +714,6 @@ discard block |
||
| 716 | 714 | /** |
| 717 | 715 | * Creates the 'default_controller' key in CodeIgniter's route array |
| 718 | 716 | * |
| 719 | - * @param string $route controller/method name |
|
| 720 | - * @param string $alias (Optional) alias of the default controller |
|
| 721 | - * |
|
| 722 | - * Due a CodeIgniter limitations, this route MAY NOT be a directory. |
|
| 723 | 717 | * |
| 724 | 718 | * @return void |
| 725 | 719 | * |
@@ -775,7 +769,7 @@ discard block |
||
| 775 | 769 | /** |
| 776 | 770 | * Get all hidden routes |
| 777 | 771 | * |
| 778 | - * @return array |
|
| 772 | + * @return Route |
|
| 779 | 773 | * |
| 780 | 774 | * @access public |
| 781 | 775 | * @static |
@@ -791,7 +785,7 @@ discard block |
||
| 791 | 785 | * This middleware actually works as uri filter since they will not check the route, |
| 792 | 786 | * just check if the current uri string matches the prefix of the route group. |
| 793 | 787 | * |
| 794 | - * @return array |
|
| 788 | + * @return Route |
|
| 795 | 789 | * |
| 796 | 790 | * @access public |
| 797 | 791 | * @static |
@@ -869,8 +863,9 @@ discard block |
||
| 869 | 863 | * This is the 'reverse' process of the improved routing, it'll take the current |
| 870 | 864 | * uri string and attempts to find a CodeIgniter route that matches with his pattern |
| 871 | 865 | * |
| 872 | - * @param string $search |
|
| 873 | 866 | * |
| 867 | + * @param Middleware $path |
|
| 868 | + * @param string $requestMethod |
|
| 874 | 869 | * @return mixed |
| 875 | 870 | */ |
| 876 | 871 | public static function getRouteByPath($path, $requestMethod = NULL) |
@@ -947,7 +942,7 @@ discard block |
||
| 947 | 942 | /** |
| 948 | 943 | * Returns an array with the valid HTTP Verbs used in routes |
| 949 | 944 | * |
| 950 | - * @return array |
|
| 945 | + * @return Route |
|
| 951 | 946 | * |
| 952 | 947 | * @access public |
| 953 | 948 | * @static |
@@ -961,7 +956,6 @@ discard block |
||
| 961 | 956 | * Set the 404 error controller ($route['404_override']) |
| 962 | 957 | * |
| 963 | 958 | * @param string $controller |
| 964 | - * @param string $namespace (Optional) |
|
| 965 | 959 | * |
| 966 | 960 | * @return void |
| 967 | 961 | * |
@@ -980,9 +974,9 @@ discard block |
||
| 980 | 974 | /** |
| 981 | 975 | * Get the 404 route |
| 982 | 976 | * |
| 983 | - * @return array $_404page |
|
| 977 | + * @return Route $_404page |
|
| 984 | 978 | * |
| 985 | - * @return object | null |
|
| 979 | + * @return Route | null |
|
| 986 | 980 | * |
| 987 | 981 | * @access public |
| 988 | 982 | * @static |
@@ -140,11 +140,13 @@ discard block |
||
| 140 | 140 | $controller = $parsedController[1]; |
| 141 | 141 | $method = $parsedController[2]; |
| 142 | 142 | |
| 143 | - if(!is_string($path)) |
|
| 144 | - show_error('Route path must be a string ', 500, 'Route error: bad route path'); |
|
| 143 | + if(!is_string($path)) { |
|
| 144 | + show_error('Route path must be a string ', 500, 'Route error: bad route path'); |
|
| 145 | + } |
|
| 145 | 146 | |
| 146 | - if(!is_string($verb)) |
|
| 147 | - show_error('Route HTTP Verb must be a string', 500, 'Route error: bad verb type'); |
|
| 147 | + if(!is_string($verb)) { |
|
| 148 | + show_error('Route HTTP Verb must be a string', 500, 'Route error: bad verb type'); |
|
| 149 | + } |
|
| 148 | 150 | |
| 149 | 151 | $verb = strtoupper($verb); |
| 150 | 152 | |
@@ -170,8 +172,7 @@ discard block |
||
| 170 | 172 | if(isset($attr['as'])) |
| 171 | 173 | { |
| 172 | 174 | $route['name'] = $attr['as']; |
| 173 | - } |
|
| 174 | - else |
|
| 175 | + } else |
|
| 175 | 176 | { |
| 176 | 177 | $route['name'] = NULL; |
| 177 | 178 | } |
@@ -181,30 +182,36 @@ discard block |
||
| 181 | 182 | $route['prefix'] = NULL; |
| 182 | 183 | $group_prefix = end(self::$prefix); |
| 183 | 184 | |
| 184 | - if($group_prefix) |
|
| 185 | - $route['prefix'] = $group_prefix.'/'; |
|
| 185 | + if($group_prefix) { |
|
| 186 | + $route['prefix'] = $group_prefix.'/'; |
|
| 187 | + } |
|
| 186 | 188 | |
| 187 | - if(isset($attr['prefix'])) |
|
| 188 | - $route['prefix'] .= $attr['prefix']; |
|
| 189 | + if(isset($attr['prefix'])) { |
|
| 190 | + $route['prefix'] .= $attr['prefix']; |
|
| 191 | + } |
|
| 189 | 192 | |
| 190 | 193 | // Setting up the namespace |
| 191 | 194 | |
| 192 | 195 | $route['namespace'] = NULL; |
| 193 | 196 | $group_namespace = end(self::$namespace); |
| 194 | 197 | |
| 195 | - if(!is_null($group_namespace)) |
|
| 196 | - $route['namespace'] = $group_namespace.'/'; |
|
| 197 | - if(isset($attr['namespace'])) |
|
| 198 | - $route['namespace'] .= $attr['namespace']; |
|
| 198 | + if(!is_null($group_namespace)) { |
|
| 199 | + $route['namespace'] = $group_namespace.'/'; |
|
| 200 | + } |
|
| 201 | + if(isset($attr['namespace'])) { |
|
| 202 | + $route['namespace'] .= $attr['namespace']; |
|
| 203 | + } |
|
| 199 | 204 | |
| 200 | 205 | $route['prefix'] = trim($route['prefix'], '/'); |
| 201 | 206 | $route['namespace'] = trim($route['namespace'],'/'); |
| 202 | 207 | |
| 203 | - if(empty($route['prefix'])) |
|
| 204 | - $route['prefix'] = NULL; |
|
| 208 | + if(empty($route['prefix'])) { |
|
| 209 | + $route['prefix'] = NULL; |
|
| 210 | + } |
|
| 205 | 211 | |
| 206 | - if(empty($route['namespace'])) |
|
| 207 | - $route['namespace'] = NULL; |
|
| 212 | + if(empty($route['namespace'])) { |
|
| 213 | + $route['namespace'] = NULL; |
|
| 214 | + } |
|
| 208 | 215 | |
| 209 | 216 | $route['middleware'] = array(); |
| 210 | 217 | |
@@ -212,14 +219,14 @@ discard block |
||
| 212 | 219 | { |
| 213 | 220 | if(is_array($attr['middleware'])) |
| 214 | 221 | { |
| 215 | - foreach($attr['middleware'] as $middleware) |
|
| 216 | - $route['middleware'][] = $middleware; # Group |
|
| 217 | - } |
|
| 218 | - elseif( is_string($attr['middleware'])) |
|
| 222 | + foreach($attr['middleware'] as $middleware) { |
|
| 223 | + $route['middleware'][] = $middleware; |
|
| 224 | + } |
|
| 225 | + # Group |
|
| 226 | + } elseif( is_string($attr['middleware'])) |
|
| 219 | 227 | { |
| 220 | 228 | $route['middleware'][] = $attr['middleware']; # Group |
| 221 | - } |
|
| 222 | - else |
|
| 229 | + } else |
|
| 223 | 230 | { |
| 224 | 231 | show_error('Route middleware must be a string or an array',500,'Route error: bad middleware format'); |
| 225 | 232 | } |
@@ -257,8 +264,7 @@ discard block |
||
| 257 | 264 | if(!$return) |
| 258 | 265 | { |
| 259 | 266 | self::$routes[] = (object) $route; |
| 260 | - } |
|
| 261 | - else |
|
| 267 | + } else |
|
| 262 | 268 | { |
| 263 | 269 | return (object) $route; |
| 264 | 270 | } |
@@ -385,8 +391,9 @@ discard block |
||
| 385 | 391 | */ |
| 386 | 392 | public static function matches($verbs, $url, $attr, $hideOriginal = FALSE) |
| 387 | 393 | { |
| 388 | - if(!is_array($verbs)) |
|
| 389 | - show_error('Route::matches() first argument must be an array of valid HTTP Verbs', 500, 'Route error: bad Route::matches() verb list'); |
|
| 394 | + if(!is_array($verbs)) { |
|
| 395 | + show_error('Route::matches() first argument must be an array of valid HTTP Verbs', 500, 'Route error: bad Route::matches() verb list'); |
|
| 396 | + } |
|
| 390 | 397 | |
| 391 | 398 | foreach($verbs as $verb) |
| 392 | 399 | { |
@@ -423,19 +430,23 @@ discard block |
||
| 423 | 430 | |
| 424 | 431 | $hideOriginal = FALSE; |
| 425 | 432 | |
| 426 | - if(isset($attr['namespace'])) |
|
| 427 | - $base_attr['namespace'] = $attr['namespace']; |
|
| 433 | + if(isset($attr['namespace'])) { |
|
| 434 | + $base_attr['namespace'] = $attr['namespace']; |
|
| 435 | + } |
|
| 428 | 436 | |
| 429 | - if(isset($attr['middleware'])) |
|
| 430 | - $base_attr['middleware'] = $attr['middleware']; |
|
| 437 | + if(isset($attr['middleware'])) { |
|
| 438 | + $base_attr['middleware'] = $attr['middleware']; |
|
| 439 | + } |
|
| 431 | 440 | |
| 432 | - if(isset($attr['hideOriginal'])) |
|
| 433 | - $hideOriginal = (bool) $attr['hideOriginal']; |
|
| 441 | + if(isset($attr['hideOriginal'])) { |
|
| 442 | + $hideOriginal = (bool) $attr['hideOriginal']; |
|
| 443 | + } |
|
| 434 | 444 | |
| 435 | 445 | $base_attr['prefix'] = strtolower($name); |
| 436 | 446 | |
| 437 | - if(isset($attr['prefix'])) |
|
| 438 | - $base_attr['prefix'] = $attr['prefix']; |
|
| 447 | + if(isset($attr['prefix'])) { |
|
| 448 | + $base_attr['prefix'] = $attr['prefix']; |
|
| 449 | + } |
|
| 439 | 450 | |
| 440 | 451 | $only = array(); |
| 441 | 452 | |
@@ -446,8 +457,7 @@ discard block |
||
| 446 | 457 | if(is_array($attr['only'])) |
| 447 | 458 | { |
| 448 | 459 | $only = $attr['only']; |
| 449 | - } |
|
| 450 | - else |
|
| 460 | + } else |
|
| 451 | 461 | { |
| 452 | 462 | $only[] = $attr['only']; |
| 453 | 463 | } |
@@ -523,8 +533,9 @@ discard block |
||
| 523 | 533 | |
| 524 | 534 | $path = $route->path; |
| 525 | 535 | |
| 526 | - if(!is_null($prefix)) |
|
| 527 | - $path = $prefix.'/'.$path; |
|
| 536 | + if(!is_null($prefix)) { |
|
| 537 | + $path = $prefix.'/'.$path; |
|
| 538 | + } |
|
| 528 | 539 | |
| 529 | 540 | /* |
| 530 | 541 | if(substr($path, 0, 1) == "/" && strlen($path) > 1) |
@@ -533,8 +544,9 @@ discard block |
||
| 533 | 544 | |
| 534 | 545 | $controller = $route->controller.'/'.$route->method; |
| 535 | 546 | |
| 536 | - if(!is_null($namespace)) |
|
| 537 | - $controller = $namespace.'/'.$controller; |
|
| 547 | + if(!is_null($namespace)) { |
|
| 548 | + $controller = $namespace.'/'.$controller; |
|
| 549 | + } |
|
| 538 | 550 | |
| 539 | 551 | $path = trim($path,'/'); |
| 540 | 552 | $controller = trim($controller,'/'); |
@@ -572,11 +584,11 @@ discard block |
||
| 572 | 584 | { |
| 573 | 585 | $args['optional'][] = $arg; |
| 574 | 586 | $argConstraint = TRUE; |
| 575 | - } |
|
| 576 | - else |
|
| 587 | + } else |
|
| 577 | 588 | { |
| 578 | - if($argConstraint) |
|
| 579 | - show_error('Optional route path argument not valid at this position', 500, 'Route error'); |
|
| 589 | + if($argConstraint) { |
|
| 590 | + show_error('Optional route path argument not valid at this position', 500, 'Route error'); |
|
| 591 | + } |
|
| 580 | 592 | $args['required'][] = $arg; |
| 581 | 593 | } |
| 582 | 594 | } |
@@ -625,12 +637,14 @@ discard block |
||
| 625 | 637 | $path = key($route); |
| 626 | 638 | $_404 = $route[$path]; |
| 627 | 639 | |
| 628 | - if(!isset($routes[$path])) |
|
| 629 | - $routes[$path] = $_404; |
|
| 640 | + if(!isset($routes[$path])) { |
|
| 641 | + $routes[$path] = $_404; |
|
| 642 | + } |
|
| 630 | 643 | } |
| 631 | 644 | |
| 632 | - if(is_null(self::$defaultController)) |
|
| 633 | - show_error('You must specify a home route: Route::home() as default controller!', 500, 'Route error: missing default controller'); |
|
| 645 | + if(is_null(self::$defaultController)) { |
|
| 646 | + show_error('You must specify a home route: Route::home() as default controller!', 500, 'Route error: missing default controller'); |
|
| 647 | + } |
|
| 634 | 648 | |
| 635 | 649 | $defaultController = self::$defaultController->compiled; |
| 636 | 650 | $defaultController = $defaultController[key($defaultController)]; |
@@ -640,8 +654,7 @@ discard block |
||
| 640 | 654 | if(is_null(self::$_404page)) |
| 641 | 655 | { |
| 642 | 656 | $routes['404_override'] = ''; |
| 643 | - } |
|
| 644 | - else |
|
| 657 | + } else |
|
| 645 | 658 | { |
| 646 | 659 | $routes['404_override'] = self::$_404page->controller; |
| 647 | 660 | } |
@@ -664,11 +677,13 @@ discard block |
||
| 664 | 677 | */ |
| 665 | 678 | public static function group($attr, $routes) |
| 666 | 679 | { |
| 667 | - if(!is_array($attr)) |
|
| 668 | - show_error('Group attribute must be a valid array'); |
|
| 680 | + if(!is_array($attr)) { |
|
| 681 | + show_error('Group attribute must be a valid array'); |
|
| 682 | + } |
|
| 669 | 683 | |
| 670 | - if(!isset($attr['prefix'])) |
|
| 671 | - show_error('You must specify an prefix!'); |
|
| 684 | + if(!isset($attr['prefix'])) { |
|
| 685 | + show_error('You must specify an prefix!'); |
|
| 686 | + } |
|
| 672 | 687 | |
| 673 | 688 | self::$prefix[] = $attr['prefix']; |
| 674 | 689 | |
@@ -680,8 +695,7 @@ discard block |
||
| 680 | 695 | if(isset($attr['hideOriginals']) && $attr['hideOriginals'] === TRUE) |
| 681 | 696 | { |
| 682 | 697 | self::$hideOriginals[] = TRUE; |
| 683 | - } |
|
| 684 | - else |
|
| 698 | + } else |
|
| 685 | 699 | { |
| 686 | 700 | self::$hideOriginals[] = FALSE; |
| 687 | 701 | } |
@@ -692,15 +706,14 @@ discard block |
||
| 692 | 706 | { |
| 693 | 707 | if(is_array($attr['middleware']) && !empty($attr['middleware'])) |
| 694 | 708 | { |
| 695 | - foreach($attr['middleware'] as $middleware) |
|
| 696 | - self::$groupMiddleware[] = [ $attr['prefix'] => $middleware ]; |
|
| 697 | - } |
|
| 698 | - else |
|
| 709 | + foreach($attr['middleware'] as $middleware) { |
|
| 710 | + self::$groupMiddleware[] = [ $attr['prefix'] => $middleware ]; |
|
| 711 | + } |
|
| 712 | + } else |
|
| 699 | 713 | { |
| 700 | 714 | self::$groupMiddleware[] = [ $attr['prefix'] => $attr['middleware'] ]; |
| 701 | 715 | } |
| 702 | - } |
|
| 703 | - else |
|
| 716 | + } else |
|
| 704 | 717 | { |
| 705 | 718 | show_error('Group middleware not valid'); |
| 706 | 719 | } |
@@ -734,14 +747,17 @@ discard block |
||
| 734 | 747 | 'as' => $as |
| 735 | 748 | ]; |
| 736 | 749 | |
| 737 | - if(!is_null($attr) && !is_array($attr)) |
|
| 738 | - show_error('Default controller attributes must be an array',500,'Route error: bad attribute type'); |
|
| 750 | + if(!is_null($attr) && !is_array($attr)) { |
|
| 751 | + show_error('Default controller attributes must be an array',500,'Route error: bad attribute type'); |
|
| 752 | + } |
|
| 739 | 753 | |
| 740 | - if(!is_null($attr)) |
|
| 741 | - $routeAttr = array_merge($routeAttr,$attr); |
|
| 754 | + if(!is_null($attr)) { |
|
| 755 | + $routeAttr = array_merge($routeAttr,$attr); |
|
| 756 | + } |
|
| 742 | 757 | |
| 743 | - if(isset($attr['prefix'])) |
|
| 744 | - show_error('Default controller may not have a prefix!',500,'Route error: prefix not allowed'); |
|
| 758 | + if(isset($attr['prefix'])) { |
|
| 759 | + show_error('Default controller may not have a prefix!',500,'Route error: prefix not allowed'); |
|
| 760 | + } |
|
| 745 | 761 | |
| 746 | 762 | self::$defaultController = self::$routes[] = self::add('GET', '/', ['uses' => $controller, 'as' => $as],TRUE, TRUE); |
| 747 | 763 | } |
@@ -759,14 +775,14 @@ discard block |
||
| 759 | 775 | if(is_null($verb)) |
| 760 | 776 | { |
| 761 | 777 | return self::$routes; |
| 762 | - } |
|
| 763 | - else |
|
| 778 | + } else |
|
| 764 | 779 | { |
| 765 | 780 | $routes = []; |
| 766 | 781 | foreach(self::$routes as $route) |
| 767 | 782 | { |
| 768 | - if($route->verb == $verb) |
|
| 769 | - $routes[] = $route; |
|
| 783 | + if($route->verb == $verb) { |
|
| 784 | + $routes[] = $route; |
|
| 785 | + } |
|
| 770 | 786 | } |
| 771 | 787 | return $routes; |
| 772 | 788 | } |
@@ -875,21 +891,24 @@ discard block |
||
| 875 | 891 | */ |
| 876 | 892 | public static function getRouteByPath($path, $requestMethod = NULL) |
| 877 | 893 | { |
| 878 | - if(is_null($requestMethod)) |
|
| 879 | - $requestMethod = $_SERVER['REQUEST_METHOD']; |
|
| 894 | + if(is_null($requestMethod)) { |
|
| 895 | + $requestMethod = $_SERVER['REQUEST_METHOD']; |
|
| 896 | + } |
|
| 880 | 897 | |
| 881 | 898 | $routes = self::getRoutes($requestMethod); |
| 882 | 899 | |
| 883 | - if(empty($routes)) |
|
| 884 | - return FALSE; |
|
| 900 | + if(empty($routes)) { |
|
| 901 | + return FALSE; |
|
| 902 | + } |
|
| 885 | 903 | |
| 886 | 904 | $founded = FALSE; |
| 887 | 905 | $matches = array(); |
| 888 | 906 | |
| 889 | 907 | $path = trim($path); |
| 890 | 908 | |
| 891 | - if($path == '') |
|
| 892 | - return self::$defaultController; |
|
| 909 | + if($path == '') { |
|
| 910 | + return self::$defaultController; |
|
| 911 | + } |
|
| 893 | 912 | |
| 894 | 913 | $wildcards = |
| 895 | 914 | [ |
@@ -916,10 +935,10 @@ discard block |
||
| 916 | 935 | |
| 917 | 936 | if($mode == 'exact') |
| 918 | 937 | { |
| 919 | - if($findPath == $compiledPath) |
|
| 920 | - return $route; |
|
| 921 | - } |
|
| 922 | - else |
|
| 938 | + if($findPath == $compiledPath) { |
|
| 939 | + return $route; |
|
| 940 | + } |
|
| 941 | + } else |
|
| 923 | 942 | { |
| 924 | 943 | $e_findPath = explode('/', $findPath); |
| 925 | 944 | $e_compiledPath = explode('/', $compiledPath); |
@@ -933,8 +952,9 @@ discard block |
||
| 933 | 952 | |
| 934 | 953 | $valid = (bool) preg_match('#^'.$reg.'$#', $e_findPath[$i]); |
| 935 | 954 | } |
| 936 | - if($valid) |
|
| 937 | - return $route; |
|
| 955 | + if($valid) { |
|
| 956 | + return $route; |
|
| 957 | + } |
|
| 938 | 958 | } |
| 939 | 959 | } |
| 940 | 960 | } |