@@ -121,17 +121,17 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | public static function add($verb, $path, $attr, $hideOriginal = TRUE, $return = FALSE) |
| 123 | 123 | { |
| 124 | - if(!is_array($attr)) |
|
| 124 | + if (!is_array($attr)) |
|
| 125 | 125 | { |
| 126 | - show_error('You must specify the route attributes as an array',500,'Route error: bad attributes'); |
|
| 126 | + show_error('You must specify the route attributes as an array', 500, 'Route error: bad attributes'); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - if(!isset($attr['uses'])) |
|
| 129 | + if (!isset($attr['uses'])) |
|
| 130 | 130 | { |
| 131 | 131 | show_error('Route requires a \'controller@method\' to be pointed and it\'s not defined in the route attributes', 500, 'Route error: missing controller'); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - if(!preg_match('/^([a-zA-Z1-9-_]+)@([a-zA-Z1-9-_]+)$/', $attr['uses'], $parsedController) !== FALSE) |
|
| 134 | + if (!preg_match('/^([a-zA-Z1-9-_]+)@([a-zA-Z1-9-_]+)$/', $attr['uses'], $parsedController) !== FALSE) |
|
| 135 | 135 | { |
| 136 | 136 | show_error('Route controller must be in format controller@method', 500, 'Route error: bad controller format'); |
| 137 | 137 | } |
@@ -140,34 +140,34 @@ discard block |
||
| 140 | 140 | $controller = $parsedController[1]; |
| 141 | 141 | $method = $parsedController[2]; |
| 142 | 142 | |
| 143 | - if(!is_string($path)) |
|
| 143 | + if (!is_string($path)) |
|
| 144 | 144 | show_error('Route path must be a string ', 500, 'Route error: bad route path'); |
| 145 | 145 | |
| 146 | - if(!is_string($verb)) |
|
| 146 | + if (!is_string($verb)) |
|
| 147 | 147 | show_error('Route HTTP Verb must be a string', 500, 'Route error: bad verb type'); |
| 148 | 148 | |
| 149 | 149 | $verb = strtoupper($verb); |
| 150 | 150 | |
| 151 | - if(!in_array($verb, self::$http_verbs,TRUE)) |
|
| 151 | + if (!in_array($verb, self::$http_verbs, TRUE)) |
|
| 152 | 152 | { |
| 153 | 153 | $errorMsg = 'Verb "'.$verb.'" is not a valid HTTP Verb, allowed verbs:<ul>'; |
| 154 | - foreach( self::$http_verbs as $validVerb ) |
|
| 154 | + foreach (self::$http_verbs as $validVerb) |
|
| 155 | 155 | { |
| 156 | 156 | $errorMsg .= '<li>'.$validVerb.'</li>'; |
| 157 | 157 | } |
| 158 | 158 | $errorMsg .= '</ul>'; |
| 159 | - show_error($errorMsg,500,'Route error: unknow method'); |
|
| 159 | + show_error($errorMsg, 500, 'Route error: unknow method'); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | $route['verb'] = $verb; |
| 163 | 163 | |
| 164 | - $path = trim($path,'/'); |
|
| 164 | + $path = trim($path, '/'); |
|
| 165 | 165 | |
| 166 | 166 | $route['path'] = $path; |
| 167 | 167 | $route['controller'] = $controller; |
| 168 | 168 | $route['method'] = $method; |
| 169 | 169 | |
| 170 | - if(isset($attr['as'])) |
|
| 170 | + if (isset($attr['as'])) |
|
| 171 | 171 | { |
| 172 | 172 | $route['name'] = $attr['as']; |
| 173 | 173 | } |
@@ -181,10 +181,10 @@ discard block |
||
| 181 | 181 | $route['prefix'] = NULL; |
| 182 | 182 | $group_prefix = end(self::$prefix); |
| 183 | 183 | |
| 184 | - if($group_prefix) |
|
| 184 | + if ($group_prefix) |
|
| 185 | 185 | $route['prefix'] = $group_prefix.'/'; |
| 186 | 186 | |
| 187 | - if(isset($attr['prefix'])) |
|
| 187 | + if (isset($attr['prefix'])) |
|
| 188 | 188 | $route['prefix'] .= $attr['prefix']; |
| 189 | 189 | |
| 190 | 190 | // Setting up the namespace |
@@ -192,36 +192,36 @@ discard block |
||
| 192 | 192 | $route['namespace'] = NULL; |
| 193 | 193 | $group_namespace = end(self::$namespace); |
| 194 | 194 | |
| 195 | - if(!is_null($group_namespace)) |
|
| 195 | + if (!is_null($group_namespace)) |
|
| 196 | 196 | $route['namespace'] = $group_namespace.'/'; |
| 197 | - if(isset($attr['namespace'])) |
|
| 197 | + if (isset($attr['namespace'])) |
|
| 198 | 198 | $route['namespace'] .= $attr['namespace']; |
| 199 | 199 | |
| 200 | 200 | $route['prefix'] = trim($route['prefix'], '/'); |
| 201 | - $route['namespace'] = trim($route['namespace'],'/'); |
|
| 201 | + $route['namespace'] = trim($route['namespace'], '/'); |
|
| 202 | 202 | |
| 203 | - if(empty($route['prefix'])) |
|
| 203 | + if (empty($route['prefix'])) |
|
| 204 | 204 | $route['prefix'] = NULL; |
| 205 | 205 | |
| 206 | - if(empty($route['namespace'])) |
|
| 206 | + if (empty($route['namespace'])) |
|
| 207 | 207 | $route['namespace'] = NULL; |
| 208 | 208 | |
| 209 | 209 | $route['middleware'] = array(); |
| 210 | 210 | |
| 211 | - if(isset($attr['middleware'])) |
|
| 211 | + if (isset($attr['middleware'])) |
|
| 212 | 212 | { |
| 213 | - if(is_array($attr['middleware'])) |
|
| 213 | + if (is_array($attr['middleware'])) |
|
| 214 | 214 | { |
| 215 | - foreach($attr['middleware'] as $middleware) |
|
| 215 | + foreach ($attr['middleware'] as $middleware) |
|
| 216 | 216 | $route['middleware'][] = $middleware; # Group |
| 217 | 217 | } |
| 218 | - elseif( is_string($attr['middleware'])) |
|
| 218 | + elseif (is_string($attr['middleware'])) |
|
| 219 | 219 | { |
| 220 | 220 | $route['middleware'][] = $attr['middleware']; # Group |
| 221 | 221 | } |
| 222 | 222 | else |
| 223 | 223 | { |
| 224 | - show_error('Route middleware must be a string or an array',500,'Route error: bad middleware format'); |
|
| 224 | + show_error('Route middleware must be a string or an array', 500, 'Route error: bad middleware format'); |
|
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | 227 | |
@@ -234,27 +234,27 @@ discard block |
||
| 234 | 234 | |
| 235 | 235 | $groupHideOriginals = end(self::$hideOriginals); |
| 236 | 236 | |
| 237 | - if($hideOriginal || $groupHideOriginals || ($compiledRoute->path != '' && $compiledRoute->path != '/' ) ) |
|
| 237 | + if ($hideOriginal || $groupHideOriginals || ($compiledRoute->path != '' && $compiledRoute->path != '/')) |
|
| 238 | 238 | { |
| 239 | 239 | $hiddenRoutePath = $controller.'/'.$method; |
| 240 | 240 | $hiddenRouteNamespace = ''; |
| 241 | 241 | |
| 242 | - if(!is_null($route['namespace'])) |
|
| 242 | + if (!is_null($route['namespace'])) |
|
| 243 | 243 | { |
| 244 | 244 | $hiddenRouteNamespace = $route['namespace'].'/'; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | $hiddenRoutePath = $hiddenRouteNamespace.$hiddenRoutePath; |
| 248 | 248 | |
| 249 | - if($method == 'index') |
|
| 249 | + if ($method == 'index') |
|
| 250 | 250 | { |
| 251 | - self::$hiddenRoutes[] = [ $hiddenRouteNamespace.$controller => function(){ show_404(); }]; |
|
| 251 | + self::$hiddenRoutes[] = [$hiddenRouteNamespace.$controller => function() { show_404(); }]; |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - self::$hiddenRoutes[] = [$hiddenRoutePath => function(){ show_404(); }]; |
|
| 254 | + self::$hiddenRoutes[] = [$hiddenRoutePath => function() { show_404(); }]; |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - if(!$return) |
|
| 257 | + if (!$return) |
|
| 258 | 258 | { |
| 259 | 259 | self::$routes[] = (object) $route; |
| 260 | 260 | } |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | */ |
| 279 | 279 | public static function get($url, $attr, $hideOriginal = TRUE) |
| 280 | 280 | { |
| 281 | - self::add('GET', $url,$attr, $hideOriginal); |
|
| 281 | + self::add('GET', $url, $attr, $hideOriginal); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | */ |
| 296 | 296 | public static function post($url, $attr, $hideOriginal = TRUE) |
| 297 | 297 | { |
| 298 | - self::add('POST', $url,$attr, $hideOriginal); |
|
| 298 | + self::add('POST', $url, $attr, $hideOriginal); |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | /** |
@@ -312,7 +312,7 @@ discard block |
||
| 312 | 312 | */ |
| 313 | 313 | public static function put($url, $attr, $hideOriginal = TRUE) |
| 314 | 314 | { |
| 315 | - self::add('PUT', $url,$attr, $hideOriginal); |
|
| 315 | + self::add('PUT', $url, $attr, $hideOriginal); |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | /** |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | */ |
| 330 | 330 | public static function patch($url, $attr, $hideOriginal = TRUE) |
| 331 | 331 | { |
| 332 | - self::add('PATCH', $url,$attr, $hideOriginal); |
|
| 332 | + self::add('PATCH', $url, $attr, $hideOriginal); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | */ |
| 347 | 347 | public static function delete($url, $attr, $hideOriginal = TRUE) |
| 348 | 348 | { |
| 349 | - self::add('DELETE', $url,$attr, $hideOriginal); |
|
| 349 | + self::add('DELETE', $url, $attr, $hideOriginal); |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | /** |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | */ |
| 364 | 364 | public static function any($url, $attr, $hideOriginal = TRUE) |
| 365 | 365 | { |
| 366 | - foreach(self::$http_verbs as $verb) |
|
| 366 | + foreach (self::$http_verbs as $verb) |
|
| 367 | 367 | { |
| 368 | 368 | $verb = strtolower($verb); |
| 369 | 369 | self::add($verb, $url, $attr, $hideOriginal); |
@@ -385,10 +385,10 @@ discard block |
||
| 385 | 385 | */ |
| 386 | 386 | public static function matches($verbs, $url, $attr, $hideOriginal = FALSE) |
| 387 | 387 | { |
| 388 | - if(!is_array($verbs)) |
|
| 388 | + if (!is_array($verbs)) |
|
| 389 | 389 | show_error('Route::matches() first argument must be an array of valid HTTP Verbs', 500, 'Route error: bad Route::matches() verb list'); |
| 390 | 390 | |
| 391 | - foreach($verbs as $verb) |
|
| 391 | + foreach ($verbs as $verb) |
|
| 392 | 392 | { |
| 393 | 393 | self::add($verb, $url, $attr, $hideOriginal); |
| 394 | 394 | } |
@@ -423,29 +423,29 @@ discard block |
||
| 423 | 423 | |
| 424 | 424 | $hideOriginal = FALSE; |
| 425 | 425 | |
| 426 | - if(isset($attr['namespace'])) |
|
| 426 | + if (isset($attr['namespace'])) |
|
| 427 | 427 | $base_attr['namespace'] = $attr['namespace']; |
| 428 | 428 | |
| 429 | - if(isset($attr['middleware'])) |
|
| 429 | + if (isset($attr['middleware'])) |
|
| 430 | 430 | $base_attr['middleware'] = $attr['middleware']; |
| 431 | 431 | |
| 432 | - if(isset($attr['hideOriginal'])) |
|
| 432 | + if (isset($attr['hideOriginal'])) |
|
| 433 | 433 | $hideOriginal = (bool) $attr['hideOriginal']; |
| 434 | 434 | |
| 435 | 435 | $base_attr['prefix'] = strtolower($name); |
| 436 | 436 | |
| 437 | - if(isset($attr['prefix'])) |
|
| 438 | - $base_attr['prefix'] = $attr['prefix']; |
|
| 437 | + if (isset($attr['prefix'])) |
|
| 438 | + $base_attr['prefix'] = $attr['prefix']; |
|
| 439 | 439 | |
| 440 | 440 | $only = array(); |
| 441 | 441 | |
| 442 | 442 | $controller = strtolower($controller); |
| 443 | 443 | |
| 444 | - if(isset($attr['only']) && (is_array($attr['only']) || is_string($attr['only']))) |
|
| 444 | + if (isset($attr['only']) && (is_array($attr['only']) || is_string($attr['only']))) |
|
| 445 | 445 | { |
| 446 | - if(is_array($attr['only'])) |
|
| 446 | + if (is_array($attr['only'])) |
|
| 447 | 447 | { |
| 448 | - $only = $attr['only']; |
|
| 448 | + $only = $attr['only']; |
|
| 449 | 449 | } |
| 450 | 450 | else |
| 451 | 451 | { |
@@ -453,43 +453,43 @@ discard block |
||
| 453 | 453 | } |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | - if(empty($only) || in_array('index', $only)) |
|
| 456 | + if (empty($only) || in_array('index', $only)) |
|
| 457 | 457 | { |
| 458 | - $route_attr = array_merge($base_attr, ['uses' => $controller.'@index', 'as' => $name.'.index']); |
|
| 458 | + $route_attr = array_merge($base_attr, ['uses' => $controller.'@index', 'as' => $name.'.index']); |
|
| 459 | 459 | self::get('/', $route_attr, $hideOriginal); |
| 460 | 460 | } |
| 461 | 461 | |
| 462 | - if(empty($only) || in_array('create', $only)) |
|
| 462 | + if (empty($only) || in_array('create', $only)) |
|
| 463 | 463 | { |
| 464 | 464 | $route_attr = array_merge($base_attr, ['uses' => $controller.'@create', 'as' => $name.'.create']); |
| 465 | 465 | self::get('create', $route_attr, $hideOriginal); |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | - if(empty($only) || in_array('store', $only)) |
|
| 468 | + if (empty($only) || in_array('store', $only)) |
|
| 469 | 469 | { |
| 470 | 470 | $route_attr = array_merge($base_attr, ['uses' => $controller.'@store', 'as' => $name.'.store']); |
| 471 | 471 | self::post('/', $route_attr, $hideOriginal); |
| 472 | 472 | } |
| 473 | 473 | |
| 474 | - if(empty($only) || in_array('show', $only)) |
|
| 474 | + if (empty($only) || in_array('show', $only)) |
|
| 475 | 475 | { |
| 476 | 476 | $route_attr = array_merge($base_attr, ['uses' => $controller.'@show', 'as' => $name.'.show']); |
| 477 | 477 | self::get('{slug}', $route_attr, $hideOriginal); |
| 478 | 478 | } |
| 479 | 479 | |
| 480 | - if(empty($only) || in_array('edit', $only)) |
|
| 480 | + if (empty($only) || in_array('edit', $only)) |
|
| 481 | 481 | { |
| 482 | 482 | $route_attr = array_merge($base_attr, ['uses' => $controller.'@edit', 'as' => $name.'.edit']); |
| 483 | 483 | self::get('{slug}/edit', $route_attr, $hideOriginal); |
| 484 | 484 | } |
| 485 | 485 | |
| 486 | - if(empty($only) || in_array('update', $only)) |
|
| 486 | + if (empty($only) || in_array('update', $only)) |
|
| 487 | 487 | { |
| 488 | 488 | $route_attr = array_merge($base_attr, ['uses' => $controller.'@update', 'as' => $name.'.update']); |
| 489 | 489 | self::matches(['PUT', 'PATCH'], '{slug}/update', $route_attr, $hideOriginal); |
| 490 | 490 | } |
| 491 | 491 | |
| 492 | - if(empty($only) || in_array('destroy', $only)) |
|
| 492 | + if (empty($only) || in_array('destroy', $only)) |
|
| 493 | 493 | { |
| 494 | 494 | $route_attr = array_merge($base_attr, ['uses' => $controller.'@destroy', 'as' => $name.'.destroy']); |
| 495 | 495 | self::delete('{slug}', $route_attr, $hideOriginal); |
@@ -511,19 +511,19 @@ discard block |
||
| 511 | 511 | $prefix = NULL; |
| 512 | 512 | $namespace = NULL; |
| 513 | 513 | |
| 514 | - if(!is_null($route->prefix)) |
|
| 514 | + if (!is_null($route->prefix)) |
|
| 515 | 515 | { |
| 516 | 516 | $prefix = $route->prefix; |
| 517 | 517 | } |
| 518 | 518 | |
| 519 | - if(!is_null($route->namespace)) |
|
| 519 | + if (!is_null($route->namespace)) |
|
| 520 | 520 | { |
| 521 | 521 | $namespace = $route->namespace; |
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | $path = $route->path; |
| 525 | 525 | |
| 526 | - if(!is_null($prefix)) |
|
| 526 | + if (!is_null($prefix)) |
|
| 527 | 527 | $path = $prefix.'/'.$path; |
| 528 | 528 | |
| 529 | 529 | /* |
@@ -533,15 +533,15 @@ discard block |
||
| 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 | - $path = trim($path,'/'); |
|
| 540 | - $controller = trim($controller,'/'); |
|
| 539 | + $path = trim($path, '/'); |
|
| 540 | + $controller = trim($controller, '/'); |
|
| 541 | 541 | |
| 542 | 542 | $replaces = |
| 543 | 543 | [ |
| 544 | - '{\((.*)\):[a-zA-Z0-9-_]*(\?}|})' => '($1)', # Custom regular expression |
|
| 544 | + '{\((.*)\):[a-zA-Z0-9-_]*(\?}|})' => '($1)', # Custom regular expression |
|
| 545 | 545 | '{num:[a-zA-Z0-9-_]*(\?}|})' => '(:num)', # (:num) route |
| 546 | 546 | '{any:[a-zA-Z0-9-_]*(\?}|})' => '(:any)', # (:any) route |
| 547 | 547 | '{[a-zA-Z0-9-_]*(\?}|})' => '(:any)', # Everything else |
@@ -549,10 +549,10 @@ discard block |
||
| 549 | 549 | |
| 550 | 550 | $foundedArgs = []; |
| 551 | 551 | |
| 552 | - foreach($replaces as $regex => $replace) |
|
| 552 | + foreach ($replaces as $regex => $replace) |
|
| 553 | 553 | { |
| 554 | 554 | $matches = []; |
| 555 | - if(preg_match_all('/'.$regex.'/', $path, $matches )) |
|
| 555 | + if (preg_match_all('/'.$regex.'/', $path, $matches)) |
|
| 556 | 556 | { |
| 557 | 557 | $foundedArgs = $matches[0]; |
| 558 | 558 | } |
@@ -566,24 +566,24 @@ discard block |
||
| 566 | 566 | $args['required'] = []; |
| 567 | 567 | $args['optional'] = []; |
| 568 | 568 | |
| 569 | - foreach($foundedArgs as $arg) |
|
| 569 | + foreach ($foundedArgs as $arg) |
|
| 570 | 570 | { |
| 571 | - if(substr($arg,-2) == '?}') |
|
| 571 | + if (substr($arg, -2) == '?}') |
|
| 572 | 572 | { |
| 573 | 573 | $args['optional'][] = $arg; |
| 574 | 574 | $argConstraint = TRUE; |
| 575 | 575 | } |
| 576 | 576 | else |
| 577 | 577 | { |
| 578 | - if($argConstraint) |
|
| 578 | + if ($argConstraint) |
|
| 579 | 579 | show_error('Optional route path argument not valid at this position', 500, 'Route error'); |
| 580 | 580 | $args['required'][] = $arg; |
| 581 | 581 | } |
| 582 | 582 | } |
| 583 | 583 | |
| 584 | - if(count($foundedArgs) > 0) |
|
| 584 | + if (count($foundedArgs) > 0) |
|
| 585 | 585 | { |
| 586 | - for($i = 0; $i < count($foundedArgs); $i++) |
|
| 586 | + for ($i = 0; $i < count($foundedArgs); $i++) |
|
| 587 | 587 | { |
| 588 | 588 | $controller .= '/$'.($i + 1); |
| 589 | 589 | } |
@@ -608,11 +608,11 @@ discard block |
||
| 608 | 608 | { |
| 609 | 609 | $routes = array(); |
| 610 | 610 | |
| 611 | - foreach(self::$routes as $index => $route) |
|
| 611 | + foreach (self::$routes as $index => $route) |
|
| 612 | 612 | { |
| 613 | 613 | $compiled = self::compileRoute($route); |
| 614 | 614 | |
| 615 | - if( !isset($routes[$compiled->path]) || $route->verb == 'GET' ) |
|
| 615 | + if (!isset($routes[$compiled->path]) || $route->verb == 'GET') |
|
| 616 | 616 | { |
| 617 | 617 | $routes[$compiled->path] = $compiled->route; |
| 618 | 618 | } |
@@ -620,16 +620,16 @@ discard block |
||
| 620 | 620 | self::$routes[$index] = (object) $route; |
| 621 | 621 | } |
| 622 | 622 | |
| 623 | - foreach(self::$hiddenRoutes as $route) |
|
| 623 | + foreach (self::$hiddenRoutes as $route) |
|
| 624 | 624 | { |
| 625 | 625 | $path = key($route); |
| 626 | 626 | $_404 = $route[$path]; |
| 627 | 627 | |
| 628 | - if(!isset($routes[$path])) |
|
| 628 | + if (!isset($routes[$path])) |
|
| 629 | 629 | $routes[$path] = $_404; |
| 630 | 630 | } |
| 631 | 631 | |
| 632 | - if(is_null(self::$defaultController)) |
|
| 632 | + if (is_null(self::$defaultController)) |
|
| 633 | 633 | show_error('You must specify a home route: Route::home() as default controller!', 500, 'Route error: missing default controller'); |
| 634 | 634 | |
| 635 | 635 | $defaultController = self::$defaultController->compiled; |
@@ -637,7 +637,7 @@ discard block |
||
| 637 | 637 | |
| 638 | 638 | $routes['default_controller'] = $defaultController; |
| 639 | 639 | |
| 640 | - if(is_null(self::$_404page)) |
|
| 640 | + if (is_null(self::$_404page)) |
|
| 641 | 641 | { |
| 642 | 642 | $routes['404_override'] = ''; |
| 643 | 643 | } |
@@ -664,20 +664,20 @@ discard block |
||
| 664 | 664 | */ |
| 665 | 665 | public static function group($attr, $routes) |
| 666 | 666 | { |
| 667 | - if(!is_array($attr)) |
|
| 667 | + if (!is_array($attr)) |
|
| 668 | 668 | show_error('Group attribute must be a valid array'); |
| 669 | 669 | |
| 670 | - if(!isset($attr['prefix'])) |
|
| 670 | + if (!isset($attr['prefix'])) |
|
| 671 | 671 | show_error('You must specify an prefix!'); |
| 672 | 672 | |
| 673 | 673 | self::$prefix[] = $attr['prefix']; |
| 674 | 674 | |
| 675 | - if(isset($attr['namespace'])) |
|
| 675 | + if (isset($attr['namespace'])) |
|
| 676 | 676 | { |
| 677 | 677 | self::$namespace[] = $attr['namespace']; |
| 678 | 678 | } |
| 679 | 679 | |
| 680 | - if(isset($attr['hideOriginals']) && $attr['hideOriginals'] === TRUE) |
|
| 680 | + if (isset($attr['hideOriginals']) && $attr['hideOriginals'] === TRUE) |
|
| 681 | 681 | { |
| 682 | 682 | self::$hideOriginals[] = TRUE; |
| 683 | 683 | } |
@@ -686,18 +686,18 @@ discard block |
||
| 686 | 686 | self::$hideOriginals[] = FALSE; |
| 687 | 687 | } |
| 688 | 688 | |
| 689 | - if(isset($attr['middleware'])) |
|
| 689 | + if (isset($attr['middleware'])) |
|
| 690 | 690 | { |
| 691 | - if(is_array($attr['middleware']) || is_string($attr['middleware'])) |
|
| 691 | + if (is_array($attr['middleware']) || is_string($attr['middleware'])) |
|
| 692 | 692 | { |
| 693 | - if(is_array($attr['middleware']) && !empty($attr['middleware'])) |
|
| 693 | + if (is_array($attr['middleware']) && !empty($attr['middleware'])) |
|
| 694 | 694 | { |
| 695 | - foreach($attr['middleware'] as $middleware) |
|
| 696 | - self::$groupMiddleware[] = [ $attr['prefix'] => $middleware ]; |
|
| 695 | + foreach ($attr['middleware'] as $middleware) |
|
| 696 | + self::$groupMiddleware[] = [$attr['prefix'] => $middleware]; |
|
| 697 | 697 | } |
| 698 | 698 | else |
| 699 | 699 | { |
| 700 | - self::$groupMiddleware[] = [ $attr['prefix'] => $attr['middleware'] ]; |
|
| 700 | + self::$groupMiddleware[] = [$attr['prefix'] => $attr['middleware']]; |
|
| 701 | 701 | } |
| 702 | 702 | } |
| 703 | 703 | else |
@@ -734,16 +734,16 @@ discard block |
||
| 734 | 734 | 'as' => $as |
| 735 | 735 | ]; |
| 736 | 736 | |
| 737 | - if(!is_null($attr) && !is_array($attr)) |
|
| 738 | - show_error('Default controller attributes must be an array',500,'Route error: bad attribute type'); |
|
| 737 | + if (!is_null($attr) && !is_array($attr)) |
|
| 738 | + show_error('Default controller attributes must be an array', 500, 'Route error: bad attribute type'); |
|
| 739 | 739 | |
| 740 | - if(!is_null($attr)) |
|
| 741 | - $routeAttr = array_merge($routeAttr,$attr); |
|
| 740 | + if (!is_null($attr)) |
|
| 741 | + $routeAttr = array_merge($routeAttr, $attr); |
|
| 742 | 742 | |
| 743 | - if(isset($attr['prefix'])) |
|
| 744 | - show_error('Default controller may not have a prefix!',500,'Route error: prefix not allowed'); |
|
| 743 | + if (isset($attr['prefix'])) |
|
| 744 | + show_error('Default controller may not have a prefix!', 500, 'Route error: prefix not allowed'); |
|
| 745 | 745 | |
| 746 | - self::$defaultController = self::$routes[] = self::add('GET', '/', ['uses' => $controller, 'as' => $as],TRUE, TRUE); |
|
| 746 | + self::$defaultController = self::$routes[] = self::add('GET', '/', ['uses' => $controller, 'as' => $as], TRUE, TRUE); |
|
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | /** |
@@ -756,16 +756,16 @@ discard block |
||
| 756 | 756 | */ |
| 757 | 757 | public static function getRoutes($verb = NULL) |
| 758 | 758 | { |
| 759 | - if(is_null($verb)) |
|
| 759 | + if (is_null($verb)) |
|
| 760 | 760 | { |
| 761 | 761 | return self::$routes; |
| 762 | 762 | } |
| 763 | 763 | else |
| 764 | 764 | { |
| 765 | 765 | $routes = []; |
| 766 | - foreach(self::$routes as $route) |
|
| 766 | + foreach (self::$routes as $route) |
|
| 767 | 767 | { |
| 768 | - if($route->verb == $verb) |
|
| 768 | + if ($route->verb == $verb) |
|
| 769 | 769 | $routes[] = $route; |
| 770 | 770 | } |
| 771 | 771 | return $routes; |
@@ -819,45 +819,45 @@ discard block |
||
| 819 | 819 | $args = func_get_args(); |
| 820 | 820 | unset($args[0]); |
| 821 | 821 | |
| 822 | - foreach(self::$routes as $route) |
|
| 822 | + foreach (self::$routes as $route) |
|
| 823 | 823 | { |
| 824 | - if($route->name == $search) |
|
| 824 | + if ($route->name == $search) |
|
| 825 | 825 | { |
| 826 | 826 | $founded = $route; |
| 827 | 827 | } |
| 828 | 828 | } |
| 829 | 829 | |
| 830 | - if(!is_null($founded)) |
|
| 830 | + if (!is_null($founded)) |
|
| 831 | 831 | { |
| 832 | 832 | $routeArgs = self::compileRoute($founded)->args; |
| 833 | 833 | $routeArgCount = count($routeArgs['required']) + count($routeArgs['optional']); |
| 834 | 834 | $routeReqArgCount = count($routeArgs['required']); |
| 835 | 835 | |
| 836 | - if(count($args) < $routeReqArgCount) |
|
| 836 | + if (count($args) < $routeReqArgCount) |
|
| 837 | 837 | { |
| 838 | 838 | $missingArgs = $routeReqArgCount - count($args); |
| 839 | 839 | throw new \Exception('Missing '.$missingArgs.' required argument'.($missingArgs != 1 ? 's' : '').' for route "'.$founded->name.'"'); |
| 840 | 840 | } |
| 841 | - if(count($args) > $routeArgCount) |
|
| 841 | + if (count($args) > $routeArgCount) |
|
| 842 | 842 | { |
| 843 | 843 | throw new \Exception('The route "'.$founded->name.'" expects maximum '.$routeArgCount.' argument'.($routeArgCount != 1 ? 's' : '').', '.count($args).' provided'); |
| 844 | 844 | } |
| 845 | 845 | |
| 846 | 846 | $path = self::compileRoute($founded)->path; |
| 847 | 847 | |
| 848 | - foreach($args as $replacement) |
|
| 848 | + foreach ($args as $replacement) |
|
| 849 | 849 | { |
| 850 | 850 | $path = preg_replace('/\((.*?)\)/', $replacement, $path, 1); |
| 851 | 851 | } |
| 852 | 852 | |
| 853 | - $argsLeft = $routeArgCount - count($args); |
|
| 853 | + $argsLeft = $routeArgCount - count($args); |
|
| 854 | 854 | |
| 855 | - for($i = $argsLeft; $i >= 0; $i--) |
|
| 855 | + for ($i = $argsLeft; $i >= 0; $i--) |
|
| 856 | 856 | { |
| 857 | 857 | $path = preg_replace('/\((.*?)\)/', '', $path, 1); |
| 858 | 858 | } |
| 859 | 859 | |
| 860 | - return base_url(trim($path,'/')); |
|
| 860 | + return base_url(trim($path, '/')); |
|
| 861 | 861 | } |
| 862 | 862 | |
| 863 | 863 | throw new \Exception('The route "'.$search.'" is not defined'); |
@@ -875,12 +875,12 @@ discard block |
||
| 875 | 875 | */ |
| 876 | 876 | public static function getRouteByPath($path, $requestMethod = NULL) |
| 877 | 877 | { |
| 878 | - if(is_null($requestMethod)) |
|
| 878 | + if (is_null($requestMethod)) |
|
| 879 | 879 | $requestMethod = $_SERVER['REQUEST_METHOD']; |
| 880 | 880 | |
| 881 | 881 | $routes = self::getRoutes($requestMethod); |
| 882 | 882 | |
| 883 | - if(empty($routes)) |
|
| 883 | + if (empty($routes)) |
|
| 884 | 884 | return FALSE; |
| 885 | 885 | |
| 886 | 886 | $founded = FALSE; |
@@ -888,7 +888,7 @@ discard block |
||
| 888 | 888 | |
| 889 | 889 | $path = trim($path); |
| 890 | 890 | |
| 891 | - if($path == '') |
|
| 891 | + if ($path == '') |
|
| 892 | 892 | return self::$defaultController; |
| 893 | 893 | |
| 894 | 894 | $wildcards = |
@@ -906,17 +906,17 @@ discard block |
||
| 906 | 906 | ]; |
| 907 | 907 | |
| 908 | 908 | |
| 909 | - foreach( ['exact' , 'regex'] as $mode) |
|
| 909 | + foreach (['exact', 'regex'] as $mode) |
|
| 910 | 910 | { |
| 911 | - foreach( [ $path, $path.'/index' ] as $findPath ) |
|
| 911 | + foreach ([$path, $path.'/index'] as $findPath) |
|
| 912 | 912 | { |
| 913 | - foreach($routes as $route) |
|
| 913 | + foreach ($routes as $route) |
|
| 914 | 914 | { |
| 915 | 915 | $compiledPath = key($route->compiled); |
| 916 | 916 | |
| 917 | - if($mode == 'exact') |
|
| 917 | + if ($mode == 'exact') |
|
| 918 | 918 | { |
| 919 | - if($findPath == $compiledPath) |
|
| 919 | + if ($findPath == $compiledPath) |
|
| 920 | 920 | return $route; |
| 921 | 921 | } |
| 922 | 922 | else |
@@ -924,16 +924,16 @@ discard block |
||
| 924 | 924 | $e_findPath = explode('/', $findPath); |
| 925 | 925 | $e_compiledPath = explode('/', $compiledPath); |
| 926 | 926 | |
| 927 | - if( count($e_findPath) == count($e_compiledPath)) |
|
| 927 | + if (count($e_findPath) == count($e_compiledPath)) |
|
| 928 | 928 | { |
| 929 | 929 | $valid = TRUE; |
| 930 | - for($i = 0; $i < count($e_findPath); $i++) |
|
| 930 | + for ($i = 0; $i < count($e_findPath); $i++) |
|
| 931 | 931 | { |
| 932 | 932 | $reg = preg_replace($wildcards, $replaces, $e_compiledPath[$i]); |
| 933 | 933 | |
| 934 | 934 | $valid = (bool) preg_match('#^'.$reg.'$#', $e_findPath[$i]); |
| 935 | 935 | } |
| 936 | - if($valid) |
|
| 936 | + if ($valid) |
|
| 937 | 937 | return $route; |
| 938 | 938 | } |
| 939 | 939 | } |