Completed
Push — master ( 546896...e1a197 )
by Anderson
02:36 queued 33s
created
src/Core/Route.php 3 patches
Doc Comments   +12 added lines, -18 removed lines patch added patch discarded remove patch
@@ -110,7 +110,6 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.
Spacing   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -121,17 +121,17 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
                     }
Please login to merge, or discard this patch.
Braces   +106 added lines, -86 removed lines patch added patch discarded remove patch
@@ -140,11 +140,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
                 }
Please login to merge, or discard this patch.