| @@ -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 | 
| @@ -130,17 +130,17 @@ discard block | ||
| 130 | 130 | */ | 
| 131 | 131 | public static function add($verb, $path, $attr, $hideOriginal = TRUE, $return = FALSE) | 
| 132 | 132 |      { | 
| 133 | - if(!is_array($attr)) | |
| 133 | + if (!is_array($attr)) | |
| 134 | 134 |          { | 
| 135 | -            show_error('You must specify the route attributes as an array',500,'Route error: bad attributes'); | |
| 135 | +            show_error('You must specify the route attributes as an array', 500, 'Route error: bad attributes'); | |
| 136 | 136 | } | 
| 137 | 137 | |
| 138 | - if(!isset($attr['uses'])) | |
| 138 | + if (!isset($attr['uses'])) | |
| 139 | 139 |          { | 
| 140 | 140 |              show_error('Route requires a \'controller@method\' to be pointed and it\'s not defined in the route attributes', 500, 'Route error: missing controller'); | 
| 141 | 141 | } | 
| 142 | 142 | |
| 143 | -        if(!preg_match('/^([a-zA-Z1-9-_]+)@([a-zA-Z1-9-_]+)$/', $attr['uses'], $parsedController) !== FALSE) | |
| 143 | +        if (!preg_match('/^([a-zA-Z1-9-_]+)@([a-zA-Z1-9-_]+)$/', $attr['uses'], $parsedController) !== FALSE) | |
| 144 | 144 |          { | 
| 145 | 145 |              show_error('Route controller must be in format controller@method', 500, 'Route error: bad controller format'); | 
| 146 | 146 | } | 
| @@ -148,28 +148,28 @@ discard block | ||
| 148 | 148 | $controller = $parsedController[1]; | 
| 149 | 149 | $method = $parsedController[2]; | 
| 150 | 150 | |
| 151 | - if(!is_string($path)) | |
| 151 | + if (!is_string($path)) | |
| 152 | 152 |              show_error('Route path must be a string ', 500, 'Route error: bad route path'); | 
| 153 | 153 | |
| 154 | - if(!is_string($verb)) | |
| 154 | + if (!is_string($verb)) | |
| 155 | 155 |              show_error('Route HTTP Verb must be a string', 500, 'Route error: bad verb type'); | 
| 156 | 156 | |
| 157 | 157 | $verb = strtoupper($verb); | 
| 158 | 158 | |
| 159 | - if(!in_array($verb, self::$http_verbs,TRUE)) | |
| 159 | + if (!in_array($verb, self::$http_verbs, TRUE)) | |
| 160 | 160 |          { | 
| 161 | 161 | $errorMsg = 'Verb "'.$verb.'" is not a valid HTTP Verb, allowed verbs:<ul>'; | 
| 162 | - foreach( self::$http_verbs as $validVerb ) | |
| 162 | + foreach (self::$http_verbs as $validVerb) | |
| 163 | 163 |              { | 
| 164 | 164 | $errorMsg .= '<li>'.$validVerb.'</li>'; | 
| 165 | 165 | } | 
| 166 | 166 | $errorMsg .= '</ul>'; | 
| 167 | - show_error($errorMsg,500,'Route error: unknow method'); | |
| 167 | + show_error($errorMsg, 500, 'Route error: unknow method'); | |
| 168 | 168 | } | 
| 169 | 169 | |
| 170 | 170 | $route['verb'] = $verb; | 
| 171 | 171 | |
| 172 | - $path = trim($path,'/'); | |
| 172 | + $path = trim($path, '/'); | |
| 173 | 173 | |
| 174 | 174 | //if($path == '') | 
| 175 | 175 | // $path = '/'; | 
| @@ -178,7 +178,7 @@ discard block | ||
| 178 | 178 | $route['controller'] = $controller; | 
| 179 | 179 | $route['method'] = $method; | 
| 180 | 180 | |
| 181 | - if(isset($attr['as'])) | |
| 181 | + if (isset($attr['as'])) | |
| 182 | 182 |          { | 
| 183 | 183 | $route['name'] = $attr['as']; | 
| 184 | 184 | } | 
| @@ -189,48 +189,48 @@ discard block | ||
| 189 | 189 | |
| 190 | 190 | $route['prefix'] = NULL; | 
| 191 | 191 | |
| 192 | - if(!is_null(self::$prefix)) | |
| 193 | - $route['prefix'] = self::$prefix; # Group | |
| 194 | - if(isset($attr['prefix'])) | |
| 192 | + if (!is_null(self::$prefix)) | |
| 193 | + $route['prefix'] = self::$prefix; # Group | |
| 194 | + if (isset($attr['prefix'])) | |
| 195 | 195 | $route['prefix'] = $attr['prefix']; # Specific (will overwrite group prefix) | 
| 196 | 196 | |
| 197 | 197 | $route['namespace'] = NULL; | 
| 198 | 198 | |
| 199 | - if(!is_null(self::$namespace)) | |
| 200 | - $route['namespace'] = self::$namespace; # Group | |
| 201 | - if(isset($attr['namespace'])) | |
| 199 | + if (!is_null(self::$namespace)) | |
| 200 | + $route['namespace'] = self::$namespace; # Group | |
| 201 | + if (isset($attr['namespace'])) | |
| 202 | 202 | $route['namespace'] = $attr['namespace']; # Specific (will overwrite group namespace) | 
| 203 | 203 | |
| 204 | 204 | # Removing trailing slashes | 
| 205 | - if(!is_null($route['prefix'])) | |
| 205 | + if (!is_null($route['prefix'])) | |
| 206 | 206 |          { | 
| 207 | - $route['prefix'] = trim($route['prefix'],'/'); | |
| 208 | - if($route['prefix'] == '') | |
| 207 | + $route['prefix'] = trim($route['prefix'], '/'); | |
| 208 | + if ($route['prefix'] == '') | |
| 209 | 209 | $route['prefix'] = NULL; | 
| 210 | 210 | } | 
| 211 | - if(!is_null($route['namespace'])) | |
| 211 | + if (!is_null($route['namespace'])) | |
| 212 | 212 |          { | 
| 213 | - $route['namespace'] = trim($route['namespace'],'/'); | |
| 214 | - if($route['namespace'] == '') | |
| 213 | + $route['namespace'] = trim($route['namespace'], '/'); | |
| 214 | + if ($route['namespace'] == '') | |
| 215 | 215 | $route['namespace'] = NULL; | 
| 216 | 216 | } | 
| 217 | 217 | |
| 218 | 218 | $route['middleware'] = array(); | 
| 219 | 219 | |
| 220 | - if(isset($attr['middleware'])) | |
| 220 | + if (isset($attr['middleware'])) | |
| 221 | 221 |          { | 
| 222 | - if(is_array($attr['middleware'])) | |
| 222 | + if (is_array($attr['middleware'])) | |
| 223 | 223 |              { | 
| 224 | - foreach($attr['middleware'] as $middleware) | |
| 224 | + foreach ($attr['middleware'] as $middleware) | |
| 225 | 225 | $route['middleware'][] = $middleware; # Group | 
| 226 | 226 | } | 
| 227 | - elseif( is_string($attr['middleware'])) | |
| 227 | + elseif (is_string($attr['middleware'])) | |
| 228 | 228 |              { | 
| 229 | 229 | $route['middleware'][] = $attr['middleware']; # Group | 
| 230 | 230 | } | 
| 231 | 231 | else | 
| 232 | 232 |              { | 
| 233 | -                show_error('Route middleware must be a string or an array',500,'Route error: bad middleware format'); | |
| 233 | +                show_error('Route middleware must be a string or an array', 500, 'Route error: bad middleware format'); | |
| 234 | 234 | } | 
| 235 | 235 | } | 
| 236 | 236 | |
| @@ -240,27 +240,27 @@ discard block | ||
| 240 | 240 | $compiledRoute->path => $compiledRoute->route | 
| 241 | 241 | ]; | 
| 242 | 242 | |
| 243 | - if($hideOriginal || self::$hideOriginals === TRUE || ($compiledRoute->path != '' && $compiledRoute->path != '/' ) ) | |
| 243 | + if ($hideOriginal || self::$hideOriginals === TRUE || ($compiledRoute->path != '' && $compiledRoute->path != '/')) | |
| 244 | 244 |          { | 
| 245 | 245 | $hiddenRoutePath = $controller.'/'.$method; | 
| 246 | 246 | $hiddenRouteNamespace = ''; | 
| 247 | 247 | |
| 248 | - if(!is_null($route['namespace'])) | |
| 248 | + if (!is_null($route['namespace'])) | |
| 249 | 249 |              { | 
| 250 | 250 | $hiddenRouteNamespace = $route['namespace'].'/'; | 
| 251 | 251 | } | 
| 252 | 252 | |
| 253 | 253 | $hiddenRoutePath = $hiddenRouteNamespace.$hiddenRoutePath; | 
| 254 | 254 | |
| 255 | - if($method == 'index') | |
| 255 | + if ($method == 'index') | |
| 256 | 256 |              { | 
| 257 | -                self::$hiddenRoutes[] = [ $hiddenRouteNamespace.$controller  => function(){ show_404(); }]; | |
| 257 | +                self::$hiddenRoutes[] = [$hiddenRouteNamespace.$controller  => function() { show_404(); }]; | |
| 258 | 258 | } | 
| 259 | 259 | |
| 260 | -            self::$hiddenRoutes[] = [$hiddenRoutePath => function(){ show_404(); }]; | |
| 260 | +            self::$hiddenRoutes[] = [$hiddenRoutePath => function() { show_404(); }]; | |
| 261 | 261 | } | 
| 262 | 262 | |
| 263 | - if(!$return) | |
| 263 | + if (!$return) | |
| 264 | 264 |          { | 
| 265 | 265 | self::$routes[] = (object) $route; | 
| 266 | 266 | } | 
| @@ -284,7 +284,7 @@ discard block | ||
| 284 | 284 | */ | 
| 285 | 285 | public static function get($url, $attr, $hideOriginal = TRUE) | 
| 286 | 286 |      { | 
| 287 | -        self::add('GET', $url,$attr, $hideOriginal); | |
| 287 | +        self::add('GET', $url, $attr, $hideOriginal); | |
| 288 | 288 | } | 
| 289 | 289 | |
| 290 | 290 | /** | 
| @@ -301,7 +301,7 @@ discard block | ||
| 301 | 301 | */ | 
| 302 | 302 | public static function post($url, $attr, $hideOriginal = TRUE) | 
| 303 | 303 |      { | 
| 304 | -        self::add('POST', $url,$attr, $hideOriginal); | |
| 304 | +        self::add('POST', $url, $attr, $hideOriginal); | |
| 305 | 305 | } | 
| 306 | 306 | |
| 307 | 307 | /** | 
| @@ -318,7 +318,7 @@ discard block | ||
| 318 | 318 | */ | 
| 319 | 319 | public static function put($url, $attr, $hideOriginal = TRUE) | 
| 320 | 320 |      { | 
| 321 | -        self::add('PUT', $url,$attr, $hideOriginal); | |
| 321 | +        self::add('PUT', $url, $attr, $hideOriginal); | |
| 322 | 322 | } | 
| 323 | 323 | |
| 324 | 324 | /** | 
| @@ -335,7 +335,7 @@ discard block | ||
| 335 | 335 | */ | 
| 336 | 336 | public static function patch($url, $attr, $hideOriginal = TRUE) | 
| 337 | 337 |      { | 
| 338 | -        self::add('PATCH', $url,$attr, $hideOriginal); | |
| 338 | +        self::add('PATCH', $url, $attr, $hideOriginal); | |
| 339 | 339 | } | 
| 340 | 340 | |
| 341 | 341 | /** | 
| @@ -352,7 +352,7 @@ discard block | ||
| 352 | 352 | */ | 
| 353 | 353 | public static function delete($url, $attr, $hideOriginal = TRUE) | 
| 354 | 354 |      { | 
| 355 | -        self::add('DELETE', $url,$attr, $hideOriginal); | |
| 355 | +        self::add('DELETE', $url, $attr, $hideOriginal); | |
| 356 | 356 | } | 
| 357 | 357 | |
| 358 | 358 | /** | 
| @@ -369,7 +369,7 @@ discard block | ||
| 369 | 369 | */ | 
| 370 | 370 | public static function any($url, $attr, $hideOriginal = TRUE) | 
| 371 | 371 |      { | 
| 372 | - foreach(self::$http_verbs as $verb) | |
| 372 | + foreach (self::$http_verbs as $verb) | |
| 373 | 373 |          { | 
| 374 | 374 | $verb = strtolower($verb); | 
| 375 | 375 | self::add($verb, $url, $attr, $hideOriginal); | 
| @@ -391,10 +391,10 @@ discard block | ||
| 391 | 391 | */ | 
| 392 | 392 | public static function matches($verbs, $url, $attr, $hideOriginal = FALSE) | 
| 393 | 393 |      { | 
| 394 | - if(!is_array($verbs)) | |
| 394 | + if (!is_array($verbs)) | |
| 395 | 395 |              show_error('Route::matches() first argument must be an array of valid HTTP Verbs', 500, 'Route error: bad Route::matches() verb list'); | 
| 396 | 396 | |
| 397 | - foreach($verbs as $verb) | |
| 397 | + foreach ($verbs as $verb) | |
| 398 | 398 |          { | 
| 399 | 399 | self::add($verb, $url, $attr, $hideOriginal); | 
| 400 | 400 | } | 
| @@ -429,25 +429,25 @@ discard block | ||
| 429 | 429 | |
| 430 | 430 | $hideOriginal = FALSE; | 
| 431 | 431 | |
| 432 | - if(isset($attr['namespace'])) | |
| 432 | + if (isset($attr['namespace'])) | |
| 433 | 433 | $base_attr['namespace'] = $attr['namespace']; | 
| 434 | 434 | |
| 435 | - if(isset($attr['middleware'])) | |
| 435 | + if (isset($attr['middleware'])) | |
| 436 | 436 | $base_attr['middleware'] = $attr['middleware']; | 
| 437 | 437 | |
| 438 | - if(isset($attr['hideOriginal'])) | |
| 438 | + if (isset($attr['hideOriginal'])) | |
| 439 | 439 | $hideOriginal = (bool) $attr['hideOriginal']; | 
| 440 | 440 | |
| 441 | - if(isset($attr['prefix'])) | |
| 442 | - $base_attr['prefix'] = $attr['prefix']; | |
| 441 | + if (isset($attr['prefix'])) | |
| 442 | + $base_attr['prefix'] = $attr['prefix']; | |
| 443 | 443 | |
| 444 | 444 | $only = array(); | 
| 445 | 445 | |
| 446 | - if(isset($attr['only']) && (is_array($attr['only']) || is_string($attr['only']))) | |
| 446 | + if (isset($attr['only']) && (is_array($attr['only']) || is_string($attr['only']))) | |
| 447 | 447 |          { | 
| 448 | - if(is_array($attr['only'])) | |
| 448 | + if (is_array($attr['only'])) | |
| 449 | 449 |              { | 
| 450 | - $only = strtolower($attr['only']); | |
| 450 | + $only = strtolower($attr['only']); | |
| 451 | 451 | } | 
| 452 | 452 | else | 
| 453 | 453 |              { | 
| @@ -455,43 +455,43 @@ discard block | ||
| 455 | 455 | } | 
| 456 | 456 | } | 
| 457 | 457 | |
| 458 | -        if(empty($only) || in_array('index', $only)) | |
| 458 | +        if (empty($only) || in_array('index', $only)) | |
| 459 | 459 |          { | 
| 460 | - $route_attr = array_merge($base_attr, ['uses' => $controller.'@index', 'as' => $name.'.index']); | |
| 460 | + $route_attr = array_merge($base_attr, ['uses' => $controller.'@index', 'as' => $name.'.index']); | |
| 461 | 461 |              self::get('/', $route_attr, $hideOriginal); | 
| 462 | 462 | } | 
| 463 | 463 | |
| 464 | -        if(empty($only) || in_array('create', $only)) | |
| 464 | +        if (empty($only) || in_array('create', $only)) | |
| 465 | 465 |          { | 
| 466 | 466 | $route_attr = array_merge($base_attr, ['uses' => $controller.'@create', 'as' => $name.'.create']); | 
| 467 | 467 |              self::get('create', $route_attr, $hideOriginal); | 
| 468 | 468 | } | 
| 469 | 469 | |
| 470 | -        if(empty($only) || in_array('store', $only)) | |
| 470 | +        if (empty($only) || in_array('store', $only)) | |
| 471 | 471 |          { | 
| 472 | 472 | $route_attr = array_merge($base_attr, ['uses' => $controller.'@store', 'as' => $name.'.store']); | 
| 473 | 473 |              self::post('/', $route_attr, $hideOriginal); | 
| 474 | 474 | } | 
| 475 | 475 | |
| 476 | -        if(empty($only) || in_array('show', $only)) | |
| 476 | +        if (empty($only) || in_array('show', $only)) | |
| 477 | 477 |          { | 
| 478 | 478 | $route_attr = array_merge($base_attr, ['uses' => $controller.'@show', 'as' => $name.'.show']); | 
| 479 | 479 |              self::get('{slug}', $route_attr, $hideOriginal); | 
| 480 | 480 | } | 
| 481 | 481 | |
| 482 | -        if(empty($only) || in_array('edit', $only)) | |
| 482 | +        if (empty($only) || in_array('edit', $only)) | |
| 483 | 483 |          { | 
| 484 | 484 | $route_attr = array_merge($base_attr, ['uses' => $controller.'@edit', 'as' => $name.'.edit']); | 
| 485 | 485 |              self::get('{slug}/edit', $route_attr, $hideOriginal); | 
| 486 | 486 | } | 
| 487 | 487 | |
| 488 | -        if(empty($only) || in_array('update', $only)) | |
| 488 | +        if (empty($only) || in_array('update', $only)) | |
| 489 | 489 |          { | 
| 490 | 490 | $route_attr = array_merge($base_attr, ['uses' => $controller.'@update', 'as' => $name.'.update']); | 
| 491 | 491 |              self::matches(['PUT', 'PATCH'], '{slug}/update', $route_attr, $hideOriginal); | 
| 492 | 492 | } | 
| 493 | 493 | |
| 494 | -        if(empty($only) || in_array('destroy', $only)) | |
| 494 | +        if (empty($only) || in_array('destroy', $only)) | |
| 495 | 495 |          { | 
| 496 | 496 | $route_attr = array_merge($base_attr, ['uses' => $controller.'@destroy', 'as' => $name.'.destroy']); | 
| 497 | 497 |              self::delete('{slug}', $route_attr, $hideOriginal); | 
| @@ -513,32 +513,32 @@ discard block | ||
| 513 | 513 | $prefix = NULL; | 
| 514 | 514 | $namespace = NULL; | 
| 515 | 515 | |
| 516 | - if(!is_null($route->prefix)) | |
| 516 | + if (!is_null($route->prefix)) | |
| 517 | 517 |          { | 
| 518 | 518 | $prefix = $route->prefix; | 
| 519 | 519 | } | 
| 520 | 520 | |
| 521 | - if(!is_null($route->namespace)) | |
| 521 | + if (!is_null($route->namespace)) | |
| 522 | 522 |          { | 
| 523 | 523 | $namespace = $route->namespace; | 
| 524 | 524 | } | 
| 525 | 525 | |
| 526 | 526 | $path = $route->path; | 
| 527 | 527 | |
| 528 | - if(!is_null($prefix)) | |
| 528 | + if (!is_null($prefix)) | |
| 529 | 529 | $path = $prefix.'/'.$path; | 
| 530 | 530 | |
| 531 | - if(substr($path, 0, 1) == "/" && strlen($path) > 1) | |
| 532 | - $path = substr($path,1); | |
| 531 | + if (substr($path, 0, 1) == "/" && strlen($path) > 1) | |
| 532 | + $path = substr($path, 1); | |
| 533 | 533 | |
| 534 | 534 | $controller = $route->controller.'/'.$route->method; | 
| 535 | 535 | |
| 536 | - if(!is_null($namespace)) | |
| 536 | + if (!is_null($namespace)) | |
| 537 | 537 | $controller = $namespace.'/'.$controller; | 
| 538 | 538 | |
| 539 | 539 | $replaces = | 
| 540 | 540 | [ | 
| 541 | -                '{\((.*)\):[a-zA-Z0-9-_]*}' => '($1)',   # Custom regular expression | |
| 541 | +                '{\((.*)\):[a-zA-Z0-9-_]*}' => '($1)', # Custom regular expression | |
| 542 | 542 |                  '{num:[a-zA-Z0-9-_]*}'      => '(:num)', # (:num) route | 
| 543 | 543 |                  '{any:[a-zA-Z0-9-_]*}'      => '(:any)', # (:any) route | 
| 544 | 544 |                  '{[a-zA-Z0-9-_]*}'          => '(:any)', # Everything else | 
| @@ -546,23 +546,23 @@ discard block | ||
| 546 | 546 | |
| 547 | 547 | $argCount = 0; | 
| 548 | 548 | |
| 549 | - foreach($replaces as $regex => $replace) | |
| 549 | + foreach ($replaces as $regex => $replace) | |
| 550 | 550 |          { | 
| 551 | 551 |              $path = preg_replace('/'.$regex.'/', $replace, $path, -1, $argCount); | 
| 552 | 552 | } | 
| 553 | 553 | |
| 554 | - if($argCount > 0) | |
| 554 | + if ($argCount > 0) | |
| 555 | 555 |          { | 
| 556 | - for($i = 0; $i < $argCount; $i++) | |
| 556 | + for ($i = 0; $i < $argCount; $i++) | |
| 557 | 557 |              { | 
| 558 | 558 | $controller .= '/$'.($i + 1); | 
| 559 | 559 | } | 
| 560 | 560 | } | 
| 561 | 561 | |
| 562 | 562 | // Removing trailing slash (it causes 404 even if the route exists, I don't know why) | 
| 563 | - if(substr($path,-1) == '/') | |
| 563 | + if (substr($path, -1) == '/') | |
| 564 | 564 |          { | 
| 565 | - $path = substr($path,0,-1); | |
| 565 | + $path = substr($path, 0, -1); | |
| 566 | 566 | } | 
| 567 | 567 | |
| 568 | 568 | return (object) [ | 
| @@ -583,11 +583,11 @@ discard block | ||
| 583 | 583 |      { | 
| 584 | 584 | $routes = array(); | 
| 585 | 585 | |
| 586 | - foreach(self::$routes as $index => $route) | |
| 586 | + foreach (self::$routes as $index => $route) | |
| 587 | 587 |          { | 
| 588 | 588 | $compiled = self::compileRoute($route); | 
| 589 | 589 | |
| 590 | - if( !isset($routes[$compiled->path]) || $route->verb == 'GET' ) | |
| 590 | + if (!isset($routes[$compiled->path]) || $route->verb == 'GET') | |
| 591 | 591 |              { | 
| 592 | 592 | $routes[$compiled->path] = $compiled->route; | 
| 593 | 593 | } | 
| @@ -595,16 +595,16 @@ discard block | ||
| 595 | 595 | self::$routes[$index] = (object) $route; | 
| 596 | 596 | } | 
| 597 | 597 | |
| 598 | - foreach(self::$hiddenRoutes as $route) | |
| 598 | + foreach (self::$hiddenRoutes as $route) | |
| 599 | 599 |          { | 
| 600 | 600 | $path = key($route); | 
| 601 | 601 | $_404 = $route[$path]; | 
| 602 | 602 | |
| 603 | - if(!isset($routes[$path])) | |
| 603 | + if (!isset($routes[$path])) | |
| 604 | 604 | $routes[$path] = $_404; | 
| 605 | 605 | } | 
| 606 | 606 | |
| 607 | - if(is_null(self::$defaultController)) | |
| 607 | + if (is_null(self::$defaultController)) | |
| 608 | 608 |              show_error('You must specify a home route: Route::home() as default controller!', 500, 'Route error: missing default controller'); | 
| 609 | 609 | |
| 610 | 610 | $defaultController = self::$defaultController->compiled; | 
| @@ -612,7 +612,7 @@ discard block | ||
| 612 | 612 | |
| 613 | 613 | $routes['default_controller'] = $defaultController; | 
| 614 | 614 | |
| 615 | - if(is_null(self::$_404page)) | |
| 615 | + if (is_null(self::$_404page)) | |
| 616 | 616 |          { | 
| 617 | 617 | $routes['404_override'] = ''; | 
| 618 | 618 | } | 
| @@ -639,20 +639,20 @@ discard block | ||
| 639 | 639 | */ | 
| 640 | 640 | public static function group($attr, $routes) | 
| 641 | 641 |      { | 
| 642 | - if(!is_array($attr)) | |
| 642 | + if (!is_array($attr)) | |
| 643 | 643 |              show_error('Group attribute must be a valid array'); | 
| 644 | 644 | |
| 645 | - if(!isset($attr['prefix'])) | |
| 645 | + if (!isset($attr['prefix'])) | |
| 646 | 646 |              show_error('You must specify an prefix!'); | 
| 647 | 647 | |
| 648 | 648 | self::$prefix = $attr['prefix']; | 
| 649 | 649 | |
| 650 | - if(isset($attr['namespace'])) | |
| 650 | + if (isset($attr['namespace'])) | |
| 651 | 651 |          { | 
| 652 | 652 | self::$namespace = $attr['namespace']; | 
| 653 | 653 | } | 
| 654 | 654 | |
| 655 | - if(isset($attr['hideOriginals']) && $attr['hideOriginals'] === TRUE) | |
| 655 | + if (isset($attr['hideOriginals']) && $attr['hideOriginals'] === TRUE) | |
| 656 | 656 |          { | 
| 657 | 657 | self::$hideOriginals = TRUE; | 
| 658 | 658 | } | 
| @@ -661,19 +661,19 @@ discard block | ||
| 661 | 661 | self::$hideOriginals = FALSE; | 
| 662 | 662 | } | 
| 663 | 663 | |
| 664 | - if(isset($attr['middleware'])) | |
| 664 | + if (isset($attr['middleware'])) | |
| 665 | 665 |          { | 
| 666 | - if(is_array($attr['middleware']) || is_string($attr['middleware'])) | |
| 666 | + if (is_array($attr['middleware']) || is_string($attr['middleware'])) | |
| 667 | 667 |              { | 
| 668 | 668 | //self::$middleware = $attr['middleware']; | 
| 669 | - if(is_array($attr['middleware']) && !empty($attr['middleware'])) | |
| 669 | + if (is_array($attr['middleware']) && !empty($attr['middleware'])) | |
| 670 | 670 |                  { | 
| 671 | - foreach($attr['middleware'] as $middleware) | |
| 672 | - self::$groupMiddleware[] = [ $attr['prefix'] => $middleware ]; | |
| 671 | + foreach ($attr['middleware'] as $middleware) | |
| 672 | + self::$groupMiddleware[] = [$attr['prefix'] => $middleware]; | |
| 673 | 673 | } | 
| 674 | 674 | else | 
| 675 | 675 |                  { | 
| 676 | - self::$groupMiddleware[] = [ $attr['prefix'] => $attr['middleware'] ]; | |
| 676 | + self::$groupMiddleware[] = [$attr['prefix'] => $attr['middleware']]; | |
| 677 | 677 | } | 
| 678 | 678 | } | 
| 679 | 679 | else | 
| @@ -684,17 +684,17 @@ discard block | ||
| 684 | 684 | |
| 685 | 685 | # Special workarround for default group controller: | 
| 686 | 686 | # Probably i'll remove it. | 
| 687 | - if(isset($attr['default'])) | |
| 687 | + if (isset($attr['default'])) | |
| 688 | 688 |          { | 
| 689 | 689 |              $url = str_ireplace('@', '/', $attr['default']); | 
| 690 | -            $uri = explode('/',$attr['default']); | |
| 690 | +            $uri = explode('/', $attr['default']); | |
| 691 | 691 | $controller = $uri[0]; | 
| 692 | 692 | $method = isset($uri[1]) ? $uri[1] : NULL; | 
| 693 | 693 | |
| 694 | - if(self::$hideOriginals === TRUE) | |
| 695 | -                self::$hiddenRoutes[] = [$controller => function(){ show_404(); }]; | |
| 694 | + if (self::$hideOriginals === TRUE) | |
| 695 | +                self::$hiddenRoutes[] = [$controller => function() { show_404(); }]; | |
| 696 | 696 | |
| 697 | - $route_attr['uses'] = $controller.( !is_null($method) ? '/'.$method : ''); | |
| 697 | + $route_attr['uses'] = $controller.(!is_null($method) ? '/'.$method : ''); | |
| 698 | 698 |              self::get('/', $route_attr); | 
| 699 | 699 | } | 
| 700 | 700 | |
| @@ -727,16 +727,16 @@ discard block | ||
| 727 | 727 | 'as' => $as | 
| 728 | 728 | ]; | 
| 729 | 729 | |
| 730 | - if(!is_null($attr) && !is_array($attr)) | |
| 731 | -            show_error('Default controller attributes must be an array',500,'Route error: bad attribute type'); | |
| 730 | + if (!is_null($attr) && !is_array($attr)) | |
| 731 | +            show_error('Default controller attributes must be an array', 500, 'Route error: bad attribute type'); | |
| 732 | 732 | |
| 733 | - if(!is_null($attr)) | |
| 734 | - $routeAttr = array_merge($routeAttr,$attr); | |
| 733 | + if (!is_null($attr)) | |
| 734 | + $routeAttr = array_merge($routeAttr, $attr); | |
| 735 | 735 | |
| 736 | - if(isset($attr['prefix'])) | |
| 737 | -            show_error('Default controller may not have a prefix!',500,'Route error: prefix not allowed'); | |
| 736 | + if (isset($attr['prefix'])) | |
| 737 | +            show_error('Default controller may not have a prefix!', 500, 'Route error: prefix not allowed'); | |
| 738 | 738 | |
| 739 | -        self::$defaultController = self::$routes[] = self::add('GET', '/', ['uses' => $controller, 'as' => $as],TRUE, TRUE); | |
| 739 | +        self::$defaultController = self::$routes[] = self::add('GET', '/', ['uses' => $controller, 'as' => $as], TRUE, TRUE); | |
| 740 | 740 | } | 
| 741 | 741 | |
| 742 | 742 | /** | 
| @@ -754,14 +754,14 @@ discard block | ||
| 754 | 754 | $baseAttr['prefix'] = 'auth'; | 
| 755 | 755 | $baseAttr['middleware'] = 'Auth'; | 
| 756 | 756 | |
| 757 | - if(!is_null($attr) && is_array($attr)) | |
| 757 | + if (!is_null($attr) && is_array($attr)) | |
| 758 | 758 |          { | 
| 759 | 759 | $baseAttr = array_merge($baseAttr, $attr); | 
| 760 | 760 | } | 
| 761 | 761 | |
| 762 | 762 | self::group($baseAttr, function() use($controller) | 
| 763 | 763 |          { | 
| 764 | - self::matches(['get','post'], '/login', ['uses' => $controller.'@login', 'as' => $controller.'.login']); | |
| 764 | + self::matches(['get', 'post'], '/login', ['uses' => $controller.'@login', 'as' => $controller.'.login']); | |
| 765 | 765 |              self::get('/logout', ['uses' => $controller.'@logout', 'as' => $controller.'.logout']); | 
| 766 | 766 | }); | 
| 767 | 767 | } | 
| @@ -822,9 +822,9 @@ discard block | ||
| 822 | 822 | */ | 
| 823 | 823 | public static function getRouteByName($search, $args = NULL) | 
| 824 | 824 |      { | 
| 825 | - foreach(self::$routes as $route) | |
| 825 | + foreach (self::$routes as $route) | |
| 826 | 826 |          { | 
| 827 | - if($route->name == $search) | |
| 827 | + if ($route->name == $search) | |
| 828 | 828 | return base_url(self::compileRoute($route)->path); | 
| 829 | 829 | } | 
| 830 | 830 | |
| @@ -845,18 +845,18 @@ discard block | ||
| 845 | 845 |      { | 
| 846 | 846 | $routes = array(); | 
| 847 | 847 | |
| 848 | - foreach(self::$routes as $route) | |
| 848 | + foreach (self::$routes as $route) | |
| 849 | 849 |          { | 
| 850 | 850 | $routes[$route->verb][] = $route; | 
| 851 | 851 | } | 
| 852 | 852 | |
| 853 | - if(empty($routes)) | |
| 853 | + if (empty($routes)) | |
| 854 | 854 | return FALSE; | 
| 855 | 855 | |
| 856 | - if(is_null($requestMethod)) | |
| 856 | + if (is_null($requestMethod)) | |
| 857 | 857 | $requestMethod = $_SERVER['REQUEST_METHOD']; | 
| 858 | 858 | |
| 859 | - if(!isset($routes[$requestMethod])) | |
| 859 | + if (!isset($routes[$requestMethod])) | |
| 860 | 860 | return FALSE; | 
| 861 | 861 | |
| 862 | 862 | $routes = $routes[$requestMethod]; | 
| @@ -866,18 +866,18 @@ discard block | ||
| 866 | 866 | |
| 867 | 867 | $path = trim($path); | 
| 868 | 868 | |
| 869 | - if($path == '') | |
| 869 | + if ($path == '') | |
| 870 | 870 |          { | 
| 871 | 871 | return self::$defaultController; | 
| 872 | 872 | } | 
| 873 | 873 | |
| 874 | - foreach( [$path, $path.'/index'] as $findPath ) | |
| 874 | + foreach ([$path, $path.'/index'] as $findPath) | |
| 875 | 875 |          { | 
| 876 | - foreach($routes as $route) | |
| 876 | + foreach ($routes as $route) | |
| 877 | 877 |              { | 
| 878 | 878 | $compiled = $route->compiled; | 
| 879 | 879 | |
| 880 | - if($findPath == key($compiled)) | |
| 880 | + if ($findPath == key($compiled)) | |
| 881 | 881 | return $route; | 
| 882 | 882 | } | 
| 883 | 883 | } | 
| @@ -64,19 +64,19 @@ 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)) | |
| 67 | + if (isset($_POST['_method']) && in_array(strtoupper($_POST['_method']), $validMethods, TRUE)) | |
| 68 | 68 | $formMethod = strtoupper($_POST['_method']); | 
| 69 | 69 | |
| 70 | - if(is_null($formMethod)) | |
| 70 | + if (is_null($formMethod)) | |
| 71 | 71 |          { | 
| 72 | 72 | $this->requestMethod = $requestMethod; | 
| 73 | 73 | } | 
| 74 | 74 | else | 
| 75 | 75 |          { | 
| 76 | - if($requestMethod == 'POST') | |
| 76 | + if ($requestMethod == 'POST') | |
| 77 | 77 | $this->requestMethod = $formMethod; | 
| 78 | 78 | |
| 79 | - if(!$this->CI->input->is_ajax_request() && $this->requestMethod == 'HEAD') | |
| 79 | + if (!$this->CI->input->is_ajax_request() && $this->requestMethod == 'HEAD') | |
| 80 | 80 | $this->requestMethod = 'POST'; | 
| 81 | 81 | } | 
| 82 | 82 | } | 
| @@ -90,14 +90,14 @@ discard block | ||
| 90 | 90 | */ | 
| 91 | 91 | public function run() | 
| 92 | 92 |      { | 
| 93 | - if(!$this->route) | |
| 93 | + if (!$this->route) | |
| 94 | 94 |          { | 
| 95 | - if(is_null(Route::get404())) | |
| 95 | + if (is_null(Route::get404())) | |
| 96 | 96 | show_404(); | 
| 97 | 97 | |
| 98 | - if(Route::get404()->controller != get_class($this->CI)) | |
| 98 | + if (Route::get404()->controller != get_class($this->CI)) | |
| 99 | 99 |              { | 
| 100 | - if(ENVIRONMENT != 'production') | |
| 100 | + if (ENVIRONMENT != 'production') | |
| 101 | 101 |                  { | 
| 102 | 102 |                      show_error('The request method '.$this->requestMethod.' is not allowed to view the resource', 403, 'Forbidden method'); | 
| 103 | 103 | } | 
| @@ -109,7 +109,7 @@ discard block | ||
| 109 | 109 | } | 
| 110 | 110 | else | 
| 111 | 111 |          { | 
| 112 | - if(method_exists($this->CI,$this->route->method)) | |
| 112 | + if (method_exists($this->CI, $this->route->method)) | |
| 113 | 113 |              { | 
| 114 | 114 |                  $this->CI->{$this->route->method}(); | 
| 115 | 115 | |
| @@ -120,7 +120,7 @@ discard block | ||
| 120 | 120 | } | 
| 121 | 121 | else | 
| 122 | 122 |              { | 
| 123 | - if(ENVIRONMENT != 'production') | |
| 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 | 126 | } |