@@ -119,7 +119,6 @@ discard block |
||
| 119 | 119 | * Generic method to add a improved route |
| 120 | 120 | * |
| 121 | 121 | * @param mixed $verb String or array of string of valid HTTP Verbs that will be accepted in this route |
| 122 | - * @param mixed $url String or array of strings that will trigger this route |
|
| 123 | 122 | * @param array $attr Associative array of route attributes |
| 124 | 123 | * @param bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside |
| 125 | 124 | * |
@@ -273,7 +272,7 @@ discard block |
||
| 273 | 272 | /** |
| 274 | 273 | * Adds a GET route, alias of Route::add('GET',$url,$attr,$hideOriginal) |
| 275 | 274 | * |
| 276 | - * @param mixed $url String or array of strings that will trigger this route |
|
| 275 | + * @param string $url String or array of strings that will trigger this route |
|
| 277 | 276 | * @param array $attr Associative array of route attributes |
| 278 | 277 | * @param bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside |
| 279 | 278 | * |
@@ -290,7 +289,7 @@ discard block |
||
| 290 | 289 | /** |
| 291 | 290 | * Adds a POST route, alias of Route::add('POST',$url,$attr,$hideOriginal) |
| 292 | 291 | * |
| 293 | - * @param mixed $url String or array of strings that will trigger this route |
|
| 292 | + * @param string $url String or array of strings that will trigger this route |
|
| 294 | 293 | * @param array $attr Associative array of route attributes |
| 295 | 294 | * @param bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside |
| 296 | 295 | * |
@@ -341,7 +340,7 @@ discard block |
||
| 341 | 340 | /** |
| 342 | 341 | * Adds a DELETE route, alias of Route::add('DELETE',$url,$attr,$hideOriginal) |
| 343 | 342 | * |
| 344 | - * @param mixed $url String or array of strings that will trigger this route |
|
| 343 | + * @param string $url String or array of strings that will trigger this route |
|
| 345 | 344 | * @param array $attr Associative array of route attributes |
| 346 | 345 | * @param bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside |
| 347 | 346 | * |
@@ -379,8 +378,8 @@ discard block |
||
| 379 | 378 | /** |
| 380 | 379 | * Adds a list of routes with the verbs contained in $verbs, alias of Route::add($verbs,$url,$attr,$hideOriginal) |
| 381 | 380 | * |
| 382 | - * @param mixed $verb String or array of string of valid HTTP Verbs that will be accepted in this route |
|
| 383 | - * @param mixed $url String or array of strings that will trigger this route |
|
| 381 | + * @param string[] $verbs String or array of string of valid HTTP Verbs that will be accepted in this route |
|
| 382 | + * @param string $url String or array of strings that will trigger this route |
|
| 384 | 383 | * @param array $attr Associative array of route attributes |
| 385 | 384 | * @param bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside |
| 386 | 385 | * |
@@ -414,7 +413,6 @@ discard block |
||
| 414 | 413 | * |
| 415 | 414 | * PLEASE NOTE: This is NOT a crud generator, just a bundle of predefined routes. |
| 416 | 415 | * |
| 417 | - * @param string $url String or array of strings that will trigger this route |
|
| 418 | 416 | * @param string $controller Controller name (only controller name) |
| 419 | 417 | * @param array $attr Associative array of route attributes |
| 420 | 418 | * |
@@ -709,10 +707,6 @@ discard block |
||
| 709 | 707 | /** |
| 710 | 708 | * Creates the 'default_controller' key in CodeIgniter's route array |
| 711 | 709 | * |
| 712 | - * @param string $route controller/method name |
|
| 713 | - * @param string $alias (Optional) alias of the default controller |
|
| 714 | - * |
|
| 715 | - * Due a CodeIgniter limitations, this route MAY NOT be a directory. |
|
| 716 | 710 | * |
| 717 | 711 | * @return void |
| 718 | 712 | * |
@@ -770,7 +764,7 @@ discard block |
||
| 770 | 764 | /** |
| 771 | 765 | * Get all the improved routes defined |
| 772 | 766 | * |
| 773 | - * @return array List of all defined routes |
|
| 767 | + * @return Route List of all defined routes |
|
| 774 | 768 | * |
| 775 | 769 | * @access public |
| 776 | 770 | * @static |
@@ -783,7 +777,7 @@ discard block |
||
| 783 | 777 | /** |
| 784 | 778 | * Get all hidden routes |
| 785 | 779 | * |
| 786 | - * @return array |
|
| 780 | + * @return Route |
|
| 787 | 781 | * |
| 788 | 782 | * @access public |
| 789 | 783 | * @static |
@@ -799,7 +793,7 @@ discard block |
||
| 799 | 793 | * This middleware actually works as uri filter since they will not check the route, |
| 800 | 794 | * just check if the current uri string matches the prefix of the route group. |
| 801 | 795 | * |
| 802 | - * @return array |
|
| 796 | + * @return Route |
|
| 803 | 797 | * |
| 804 | 798 | * @access public |
| 805 | 799 | * @static |
@@ -837,8 +831,9 @@ discard block |
||
| 837 | 831 | * This is the 'reverse' process of the improved routing, it'll take the current |
| 838 | 832 | * uri string and attempts to find a CodeIgniter route that matches with his pattern |
| 839 | 833 | * |
| 840 | - * @param string $search The current uri string |
|
| 841 | 834 | * |
| 835 | + * @param Middleware $path |
|
| 836 | + * @param string $requestMethod |
|
| 842 | 837 | * @return mixed |
| 843 | 838 | */ |
| 844 | 839 | public static function getRouteByPath($path, $requestMethod = NULL) |
@@ -888,7 +883,7 @@ discard block |
||
| 888 | 883 | /** |
| 889 | 884 | * Returns an array with the valid HTTP Verbs used in routes |
| 890 | 885 | * |
| 891 | - * @return array |
|
| 886 | + * @return Route |
|
| 892 | 887 | * |
| 893 | 888 | * @access public |
| 894 | 889 | * @static |
@@ -903,7 +898,6 @@ discard block |
||
| 903 | 898 | * Set the 404 error controller ($route['404_override']) |
| 904 | 899 | * |
| 905 | 900 | * @param string $controller |
| 906 | - * @param string $namespace (Optional) |
|
| 907 | 901 | * |
| 908 | 902 | * @return void |
| 909 | 903 | * |
@@ -922,9 +916,9 @@ discard block |
||
| 922 | 916 | /** |
| 923 | 917 | * Get the 404 route |
| 924 | 918 | * |
| 925 | - * @return array $_404page |
|
| 919 | + * @return Route $_404page |
|
| 926 | 920 | * |
| 927 | - * @return object | null |
|
| 921 | + * @return Route | null |
|
| 928 | 922 | * |
| 929 | 923 | * @access public |
| 930 | 924 | * @static |
@@ -148,11 +148,13 @@ discard block |
||
| 148 | 148 | $controller = $parsedController[1]; |
| 149 | 149 | $method = $parsedController[2]; |
| 150 | 150 | |
| 151 | - if(!is_string($path)) |
|
| 152 | - show_error('Route path must be a string ', 500, 'Route error: bad route path'); |
|
| 151 | + if(!is_string($path)) { |
|
| 152 | + show_error('Route path must be a string ', 500, 'Route error: bad route path'); |
|
| 153 | + } |
|
| 153 | 154 | |
| 154 | - if(!is_string($verb)) |
|
| 155 | - show_error('Route HTTP Verb must be a string', 500, 'Route error: bad verb type'); |
|
| 155 | + if(!is_string($verb)) { |
|
| 156 | + show_error('Route HTTP Verb must be a string', 500, 'Route error: bad verb type'); |
|
| 157 | + } |
|
| 156 | 158 | |
| 157 | 159 | $verb = strtoupper($verb); |
| 158 | 160 | |
@@ -181,38 +183,47 @@ discard block |
||
| 181 | 183 | if(isset($attr['as'])) |
| 182 | 184 | { |
| 183 | 185 | $route['name'] = $attr['as']; |
| 184 | - } |
|
| 185 | - else |
|
| 186 | + } else |
|
| 186 | 187 | { |
| 187 | 188 | $route['name'] = NULL; |
| 188 | 189 | } |
| 189 | 190 | |
| 190 | 191 | $route['prefix'] = NULL; |
| 191 | 192 | |
| 192 | - if(!is_null(self::$prefix)) |
|
| 193 | - $route['prefix'] = self::$prefix; # Group |
|
| 194 | - if(isset($attr['prefix'])) |
|
| 195 | - $route['prefix'] = $attr['prefix']; # Specific (will overwrite group prefix) |
|
| 193 | + if(!is_null(self::$prefix)) { |
|
| 194 | + $route['prefix'] = self::$prefix; |
|
| 195 | + } |
|
| 196 | + # Group |
|
| 197 | + if(isset($attr['prefix'])) { |
|
| 198 | + $route['prefix'] = $attr['prefix']; |
|
| 199 | + } |
|
| 200 | + # Specific (will overwrite group prefix) |
|
| 196 | 201 | |
| 197 | 202 | $route['namespace'] = NULL; |
| 198 | 203 | |
| 199 | - if(!is_null(self::$namespace)) |
|
| 200 | - $route['namespace'] = self::$namespace; # Group |
|
| 201 | - if(isset($attr['namespace'])) |
|
| 202 | - $route['namespace'] = $attr['namespace']; # Specific (will overwrite group namespace) |
|
| 204 | + if(!is_null(self::$namespace)) { |
|
| 205 | + $route['namespace'] = self::$namespace; |
|
| 206 | + } |
|
| 207 | + # Group |
|
| 208 | + if(isset($attr['namespace'])) { |
|
| 209 | + $route['namespace'] = $attr['namespace']; |
|
| 210 | + } |
|
| 211 | + # Specific (will overwrite group namespace) |
|
| 203 | 212 | |
| 204 | 213 | # Removing trailing slashes |
| 205 | 214 | if(!is_null($route['prefix'])) |
| 206 | 215 | { |
| 207 | 216 | $route['prefix'] = trim($route['prefix'],'/'); |
| 208 | - if($route['prefix'] == '') |
|
| 209 | - $route['prefix'] = NULL; |
|
| 217 | + if($route['prefix'] == '') { |
|
| 218 | + $route['prefix'] = NULL; |
|
| 219 | + } |
|
| 210 | 220 | } |
| 211 | 221 | if(!is_null($route['namespace'])) |
| 212 | 222 | { |
| 213 | 223 | $route['namespace'] = trim($route['namespace'],'/'); |
| 214 | - if($route['namespace'] == '') |
|
| 215 | - $route['namespace'] = NULL; |
|
| 224 | + if($route['namespace'] == '') { |
|
| 225 | + $route['namespace'] = NULL; |
|
| 226 | + } |
|
| 216 | 227 | } |
| 217 | 228 | |
| 218 | 229 | $route['middleware'] = array(); |
@@ -221,14 +232,14 @@ discard block |
||
| 221 | 232 | { |
| 222 | 233 | if(is_array($attr['middleware'])) |
| 223 | 234 | { |
| 224 | - foreach($attr['middleware'] as $middleware) |
|
| 225 | - $route['middleware'][] = $middleware; # Group |
|
| 226 | - } |
|
| 227 | - elseif( is_string($attr['middleware'])) |
|
| 235 | + foreach($attr['middleware'] as $middleware) { |
|
| 236 | + $route['middleware'][] = $middleware; |
|
| 237 | + } |
|
| 238 | + # Group |
|
| 239 | + } elseif( is_string($attr['middleware'])) |
|
| 228 | 240 | { |
| 229 | 241 | $route['middleware'][] = $attr['middleware']; # Group |
| 230 | - } |
|
| 231 | - else |
|
| 242 | + } else |
|
| 232 | 243 | { |
| 233 | 244 | show_error('Route middleware must be a string or an array',500,'Route error: bad middleware format'); |
| 234 | 245 | } |
@@ -263,8 +274,7 @@ discard block |
||
| 263 | 274 | if(!$return) |
| 264 | 275 | { |
| 265 | 276 | self::$routes[] = (object) $route; |
| 266 | - } |
|
| 267 | - else |
|
| 277 | + } else |
|
| 268 | 278 | { |
| 269 | 279 | return (object) $route; |
| 270 | 280 | } |
@@ -391,8 +401,9 @@ discard block |
||
| 391 | 401 | */ |
| 392 | 402 | public static function matches($verbs, $url, $attr, $hideOriginal = FALSE) |
| 393 | 403 | { |
| 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'); |
|
| 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'); |
|
| 406 | + } |
|
| 396 | 407 | |
| 397 | 408 | foreach($verbs as $verb) |
| 398 | 409 | { |
@@ -429,17 +440,21 @@ discard block |
||
| 429 | 440 | |
| 430 | 441 | $hideOriginal = FALSE; |
| 431 | 442 | |
| 432 | - if(isset($attr['namespace'])) |
|
| 433 | - $base_attr['namespace'] = $attr['namespace']; |
|
| 443 | + if(isset($attr['namespace'])) { |
|
| 444 | + $base_attr['namespace'] = $attr['namespace']; |
|
| 445 | + } |
|
| 434 | 446 | |
| 435 | - if(isset($attr['middleware'])) |
|
| 436 | - $base_attr['middleware'] = $attr['middleware']; |
|
| 447 | + if(isset($attr['middleware'])) { |
|
| 448 | + $base_attr['middleware'] = $attr['middleware']; |
|
| 449 | + } |
|
| 437 | 450 | |
| 438 | - if(isset($attr['hideOriginal'])) |
|
| 439 | - $hideOriginal = (bool) $attr['hideOriginal']; |
|
| 451 | + if(isset($attr['hideOriginal'])) { |
|
| 452 | + $hideOriginal = (bool) $attr['hideOriginal']; |
|
| 453 | + } |
|
| 440 | 454 | |
| 441 | - if(isset($attr['prefix'])) |
|
| 442 | - $base_attr['prefix'] = $attr['prefix']; |
|
| 455 | + if(isset($attr['prefix'])) { |
|
| 456 | + $base_attr['prefix'] = $attr['prefix']; |
|
| 457 | + } |
|
| 443 | 458 | |
| 444 | 459 | $only = array(); |
| 445 | 460 | |
@@ -448,8 +463,7 @@ discard block |
||
| 448 | 463 | if(is_array($attr['only'])) |
| 449 | 464 | { |
| 450 | 465 | $only = strtolower($attr['only']); |
| 451 | - } |
|
| 452 | - else |
|
| 466 | + } else |
|
| 453 | 467 | { |
| 454 | 468 | $only[] = strtolower($attr['only']); |
| 455 | 469 | } |
@@ -525,16 +539,19 @@ discard block |
||
| 525 | 539 | |
| 526 | 540 | $path = $route->path; |
| 527 | 541 | |
| 528 | - if(!is_null($prefix)) |
|
| 529 | - $path = $prefix.'/'.$path; |
|
| 542 | + if(!is_null($prefix)) { |
|
| 543 | + $path = $prefix.'/'.$path; |
|
| 544 | + } |
|
| 530 | 545 | |
| 531 | - if(substr($path, 0, 1) == "/" && strlen($path) > 1) |
|
| 532 | - $path = substr($path,1); |
|
| 546 | + if(substr($path, 0, 1) == "/" && strlen($path) > 1) { |
|
| 547 | + $path = substr($path,1); |
|
| 548 | + } |
|
| 533 | 549 | |
| 534 | 550 | $controller = $route->controller.'/'.$route->method; |
| 535 | 551 | |
| 536 | - if(!is_null($namespace)) |
|
| 537 | - $controller = $namespace.'/'.$controller; |
|
| 552 | + if(!is_null($namespace)) { |
|
| 553 | + $controller = $namespace.'/'.$controller; |
|
| 554 | + } |
|
| 538 | 555 | |
| 539 | 556 | $replaces = |
| 540 | 557 | [ |
@@ -600,12 +617,14 @@ discard block |
||
| 600 | 617 | $path = key($route); |
| 601 | 618 | $_404 = $route[$path]; |
| 602 | 619 | |
| 603 | - if(!isset($routes[$path])) |
|
| 604 | - $routes[$path] = $_404; |
|
| 620 | + if(!isset($routes[$path])) { |
|
| 621 | + $routes[$path] = $_404; |
|
| 622 | + } |
|
| 605 | 623 | } |
| 606 | 624 | |
| 607 | - if(is_null(self::$defaultController)) |
|
| 608 | - show_error('You must specify a home route: Route::home() as default controller!', 500, 'Route error: missing default controller'); |
|
| 625 | + if(is_null(self::$defaultController)) { |
|
| 626 | + show_error('You must specify a home route: Route::home() as default controller!', 500, 'Route error: missing default controller'); |
|
| 627 | + } |
|
| 609 | 628 | |
| 610 | 629 | $defaultController = self::$defaultController->compiled; |
| 611 | 630 | $defaultController = $defaultController[key($defaultController)]; |
@@ -615,8 +634,7 @@ discard block |
||
| 615 | 634 | if(is_null(self::$_404page)) |
| 616 | 635 | { |
| 617 | 636 | $routes['404_override'] = ''; |
| 618 | - } |
|
| 619 | - else |
|
| 637 | + } else |
|
| 620 | 638 | { |
| 621 | 639 | $routes['404_override'] = self::$_404page->controller; |
| 622 | 640 | } |
@@ -639,11 +657,13 @@ discard block |
||
| 639 | 657 | */ |
| 640 | 658 | public static function group($attr, $routes) |
| 641 | 659 | { |
| 642 | - if(!is_array($attr)) |
|
| 643 | - show_error('Group attribute must be a valid array'); |
|
| 660 | + if(!is_array($attr)) { |
|
| 661 | + show_error('Group attribute must be a valid array'); |
|
| 662 | + } |
|
| 644 | 663 | |
| 645 | - if(!isset($attr['prefix'])) |
|
| 646 | - show_error('You must specify an prefix!'); |
|
| 664 | + if(!isset($attr['prefix'])) { |
|
| 665 | + show_error('You must specify an prefix!'); |
|
| 666 | + } |
|
| 647 | 667 | |
| 648 | 668 | self::$prefix = $attr['prefix']; |
| 649 | 669 | |
@@ -655,8 +675,7 @@ discard block |
||
| 655 | 675 | if(isset($attr['hideOriginals']) && $attr['hideOriginals'] === TRUE) |
| 656 | 676 | { |
| 657 | 677 | self::$hideOriginals = TRUE; |
| 658 | - } |
|
| 659 | - else |
|
| 678 | + } else |
|
| 660 | 679 | { |
| 661 | 680 | self::$hideOriginals = FALSE; |
| 662 | 681 | } |
@@ -668,15 +687,14 @@ discard block |
||
| 668 | 687 | //self::$middleware = $attr['middleware']; |
| 669 | 688 | if(is_array($attr['middleware']) && !empty($attr['middleware'])) |
| 670 | 689 | { |
| 671 | - foreach($attr['middleware'] as $middleware) |
|
| 672 | - self::$groupMiddleware[] = [ $attr['prefix'] => $middleware ]; |
|
| 673 | - } |
|
| 674 | - else |
|
| 690 | + foreach($attr['middleware'] as $middleware) { |
|
| 691 | + self::$groupMiddleware[] = [ $attr['prefix'] => $middleware ]; |
|
| 692 | + } |
|
| 693 | + } else |
|
| 675 | 694 | { |
| 676 | 695 | self::$groupMiddleware[] = [ $attr['prefix'] => $attr['middleware'] ]; |
| 677 | 696 | } |
| 678 | - } |
|
| 679 | - else |
|
| 697 | + } else |
|
| 680 | 698 | { |
| 681 | 699 | show_error('Group middleware not valid'); |
| 682 | 700 | } |
@@ -691,8 +709,10 @@ discard block |
||
| 691 | 709 | $controller = $uri[0]; |
| 692 | 710 | $method = isset($uri[1]) ? $uri[1] : NULL; |
| 693 | 711 | |
| 694 | - if(self::$hideOriginals === TRUE) |
|
| 695 | - self::$hiddenRoutes[] = [$controller => function(){ show_404(); }]; |
|
| 712 | + if(self::$hideOriginals === TRUE) { |
|
| 713 | + self::$hiddenRoutes[] = [$controller => function(){ show_404(); |
|
| 714 | + } |
|
| 715 | + }]; |
|
| 696 | 716 | |
| 697 | 717 | $route_attr['uses'] = $controller.( !is_null($method) ? '/'.$method : ''); |
| 698 | 718 | self::get('/', $route_attr); |
@@ -727,14 +747,17 @@ discard block |
||
| 727 | 747 | 'as' => $as |
| 728 | 748 | ]; |
| 729 | 749 | |
| 730 | - if(!is_null($attr) && !is_array($attr)) |
|
| 731 | - 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 | + } |
|
| 732 | 753 | |
| 733 | - if(!is_null($attr)) |
|
| 734 | - $routeAttr = array_merge($routeAttr,$attr); |
|
| 754 | + if(!is_null($attr)) { |
|
| 755 | + $routeAttr = array_merge($routeAttr,$attr); |
|
| 756 | + } |
|
| 735 | 757 | |
| 736 | - if(isset($attr['prefix'])) |
|
| 737 | - 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 | + } |
|
| 738 | 761 | |
| 739 | 762 | self::$defaultController = self::$routes[] = self::add('GET', '/', ['uses' => $controller, 'as' => $as],TRUE, TRUE); |
| 740 | 763 | } |
@@ -824,8 +847,9 @@ discard block |
||
| 824 | 847 | { |
| 825 | 848 | foreach(self::$routes as $route) |
| 826 | 849 | { |
| 827 | - if($route->name == $search) |
|
| 828 | - return base_url(self::compileRoute($route)->path); |
|
| 850 | + if($route->name == $search) { |
|
| 851 | + return base_url(self::compileRoute($route)->path); |
|
| 852 | + } |
|
| 829 | 853 | } |
| 830 | 854 | |
| 831 | 855 | show_error('The route "'.$search.'" is not defined', 500, 'Route error'); |
@@ -850,14 +874,17 @@ discard block |
||
| 850 | 874 | $routes[$route->verb][] = $route; |
| 851 | 875 | } |
| 852 | 876 | |
| 853 | - if(empty($routes)) |
|
| 854 | - return FALSE; |
|
| 877 | + if(empty($routes)) { |
|
| 878 | + return FALSE; |
|
| 879 | + } |
|
| 855 | 880 | |
| 856 | - if(is_null($requestMethod)) |
|
| 857 | - $requestMethod = $_SERVER['REQUEST_METHOD']; |
|
| 881 | + if(is_null($requestMethod)) { |
|
| 882 | + $requestMethod = $_SERVER['REQUEST_METHOD']; |
|
| 883 | + } |
|
| 858 | 884 | |
| 859 | - if(!isset($routes[$requestMethod])) |
|
| 860 | - return FALSE; |
|
| 885 | + if(!isset($routes[$requestMethod])) { |
|
| 886 | + return FALSE; |
|
| 887 | + } |
|
| 861 | 888 | |
| 862 | 889 | $routes = $routes[$requestMethod]; |
| 863 | 890 | |
@@ -877,8 +904,9 @@ discard block |
||
| 877 | 904 | { |
| 878 | 905 | $compiled = $route->compiled; |
| 879 | 906 | |
| 880 | - if($findPath == key($compiled)) |
|
| 881 | - return $route; |
|
| 907 | + if($findPath == key($compiled)) { |
|
| 908 | + return $route; |
|
| 909 | + } |
|
| 882 | 910 | } |
| 883 | 911 | } |
| 884 | 912 | |
@@ -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 | } |