Completed
Push — master ( bfcd30...39dce4 )
by Anderson
49:49
created
src/Core/Route.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -570,12 +570,12 @@  discard block
 block discarded – undo
570 570
 
571 571
             foreach ($replaces as $regex => $replace)
572 572
             {
573
-                if($customRegex)
573
+                if ($customRegex)
574 574
                     continue;
575 575
 
576 576
                 $matches = [];
577 577
 
578
-                if(preg_match('/^\{(.*)\}$/', $segment))
578
+                if (preg_match('/^\{(.*)\}$/', $segment))
579 579
                 {
580 580
                     $foundedArgs[$key] = $segment;
581 581
                 }
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
                 $c = 0;
584 584
                 $segment = preg_replace('/'.$regex.'/', $replace, $segment, 1, $c);
585 585
 
586
-                if( $regex == array_keys($replaces)[0] && $c > 0)
586
+                if ($regex == array_keys($replaces)[0] && $c > 0)
587 587
                     $customRegex = TRUE;
588 588
             }
589 589
         }
@@ -809,11 +809,11 @@  discard block
 block discarded – undo
809 809
         array_pop(self::$prefix);
810 810
         array_pop(self::$hideOriginals);
811 811
 
812
-        if( isset($attr['namespace']) )
812
+        if (isset($attr['namespace']))
813 813
             array_pop(self::$namespace);
814 814
 
815 815
         // Flushing nested middleware:
816
-        for($i = 0; $i < $mcount; $i++)
816
+        for ($i = 0; $i < $mcount; $i++)
817 817
             array_pop(self::$middleware);
818 818
     }
819 819
 
@@ -1033,7 +1033,7 @@  discard block
 block discarded – undo
1033 1033
                             {
1034 1034
                                 for ($i = 0; $i < $c_e_findPath; $i++)
1035 1035
                                 {
1036
-                                    if(in_array($i, $skip_seg))
1036
+                                    if (in_array($i, $skip_seg))
1037 1037
                                         continue;
1038 1038
 
1039 1039
                                     if ($valid)
Please login to merge, or discard this patch.
Braces   +126 added lines, -94 removed lines patch added patch discarded remove patch
@@ -146,11 +146,13 @@  discard block
 block discarded – undo
146 146
         $controller = $parsedController[1];
147 147
         $method     = $parsedController[2];
148 148
 
149
-        if (!is_string($path))
150
-            show_error('Route path must be a string ', 500, 'Route error: bad route path');
149
+        if (!is_string($path)) {
150
+                    show_error('Route path must be a string ', 500, 'Route error: bad route path');
151
+        }
151 152
 
152
-        if (!is_string($verb))
153
-            show_error('Route HTTP Verb must be a string', 500, 'Route error: bad verb type');
153
+        if (!is_string($verb)) {
154
+                    show_error('Route HTTP Verb must be a string', 500, 'Route error: bad verb type');
155
+        }
154 156
 
155 157
         $verb = strtoupper($verb);
156 158
 
@@ -186,30 +188,36 @@  discard block
 block discarded – undo
186 188
         $route['prefix'] = NULL;
187 189
         $group_prefix = implode('/', self::$prefix);
188 190
 
189
-        if ($group_prefix)
190
-            $route['prefix'] = $group_prefix.'/';
191
+        if ($group_prefix) {
192
+                    $route['prefix'] = $group_prefix.'/';
193
+        }
191 194
 
192
-        if (isset($attr['prefix']))
193
-            $route['prefix'] .= $attr['prefix'];
195
+        if (isset($attr['prefix'])) {
196
+                    $route['prefix'] .= $attr['prefix'];
197
+        }
194 198
 
195 199
         // Setting up the namespace
196 200
 
197 201
         $route['namespace'] = NULL;
198 202
         $group_namespace = implode('/', self::$namespace);
199 203
 
200
-        if (!is_null($group_namespace))
201
-            $route['namespace'] = $group_namespace.'/';
202
-        if (isset($attr['namespace']))
203
-            $route['namespace'] .= $attr['namespace'];
204
+        if (!is_null($group_namespace)) {
205
+                    $route['namespace'] = $group_namespace.'/';
206
+        }
207
+        if (isset($attr['namespace'])) {
208
+                    $route['namespace'] .= $attr['namespace'];
209
+        }
204 210
 
205 211
         $route['prefix']    = trim($route['prefix'], '/');
206 212
         $route['namespace'] = trim($route['namespace'], '/');
207 213
 
208
-        if (empty($route['prefix']))
209
-            $route['prefix'] = NULL;
214
+        if (empty($route['prefix'])) {
215
+                    $route['prefix'] = NULL;
216
+        }
210 217
 
211
-        if (empty($route['namespace']))
212
-            $route['namespace'] = NULL;
218
+        if (empty($route['namespace'])) {
219
+                    $route['namespace'] = NULL;
220
+        }
213 221
 
214 222
         // Route middleware
215 223
         $route['middleware'] = [];
@@ -219,14 +227,14 @@  discard block
 block discarded – undo
219 227
         {
220 228
             if (is_array($attr['middleware']))
221 229
             {
222
-                foreach ($attr['middleware'] as $middleware)
223
-                    $route['middleware'][] = $middleware; # Group
224
-            }
225
-            elseif (is_string($attr['middleware']))
230
+                foreach ($attr['middleware'] as $middleware) {
231
+                                    $route['middleware'][] = $middleware;
232
+                }
233
+                # Group
234
+            } elseif (is_string($attr['middleware']))
226 235
             {
227 236
                 $route['middleware'][] = $attr['middleware']; # Group
228
-            }
229
-            else
237
+            } else
230 238
             {
231 239
                 show_error('Route middleware must be a string or an array', 500, 'Route error: bad middleware format');
232 240
             }
@@ -398,8 +406,9 @@  discard block
 block discarded – undo
398 406
      */
399 407
     public static function matches($verbs, $url, $attr, $hideOriginal = FALSE)
400 408
     {
401
-        if (!is_array($verbs))
402
-            show_error('Route::matches() first argument must be an array of valid HTTP Verbs', 500, 'Route error: bad Route::matches() verb list');
409
+        if (!is_array($verbs)) {
410
+                    show_error('Route::matches() first argument must be an array of valid HTTP Verbs', 500, 'Route error: bad Route::matches() verb list');
411
+        }
403 412
 
404 413
         foreach ($verbs as $verb)
405 414
         {
@@ -427,19 +436,23 @@  discard block
 block discarded – undo
427 436
 
428 437
         $hideOriginal = FALSE;
429 438
 
430
-        if (isset($attr['namespace']))
431
-            $base_attr['namespace']  = $attr['namespace'];
439
+        if (isset($attr['namespace'])) {
440
+                    $base_attr['namespace']  = $attr['namespace'];
441
+        }
432 442
 
433
-        if (isset($attr['middleware']))
434
-            $base_attr['middleware'] = $attr['middleware'];
443
+        if (isset($attr['middleware'])) {
444
+                    $base_attr['middleware'] = $attr['middleware'];
445
+        }
435 446
 
436
-        if (isset($attr['hideOriginal']))
437
-            $hideOriginal = (bool) $attr['hideOriginal'];
447
+        if (isset($attr['hideOriginal'])) {
448
+                    $hideOriginal = (bool) $attr['hideOriginal'];
449
+        }
438 450
 
439 451
         $base_attr['prefix'] = strtolower($name);
440 452
 
441
-        if (isset($attr['prefix']))
442
-            $base_attr['prefix'] = $attr['prefix'];
453
+        if (isset($attr['prefix'])) {
454
+                    $base_attr['prefix'] = $attr['prefix'];
455
+        }
443 456
 
444 457
         $only = [];
445 458
 
@@ -450,8 +463,7 @@  discard block
 block discarded – undo
450 463
             if (is_array($attr['only']))
451 464
             {
452 465
                 $only = $attr['only'];
453
-            }
454
-            else
466
+            } else
455 467
             {
456 468
                 $only[] = $attr['only'];
457 469
             }
@@ -528,13 +540,15 @@  discard block
 block discarded – undo
528 540
 
529 541
         $path = $route->path;
530 542
 
531
-        if (!is_null($prefix))
532
-            $path = $prefix.'/'.$path;
543
+        if (!is_null($prefix)) {
544
+                    $path = $prefix.'/'.$path;
545
+        }
533 546
 
534 547
         $controller = $route->controller.'/'.$route->method;
535 548
 
536
-        if (!is_null($namespace))
537
-            $controller = $namespace.'/'.$controller;
549
+        if (!is_null($namespace)) {
550
+                    $controller = $namespace.'/'.$controller;
551
+        }
538 552
 
539 553
         $path       = trim($path, '/');
540 554
         $controller = trim($controller, '/');
@@ -570,8 +584,9 @@  discard block
 block discarded – undo
570 584
 
571 585
             foreach ($replaces as $regex => $replace)
572 586
             {
573
-                if($customRegex)
574
-                    continue;
587
+                if($customRegex) {
588
+                                    continue;
589
+                }
575 590
 
576 591
                 $matches = [];
577 592
 
@@ -583,8 +598,9 @@  discard block
 block discarded – undo
583 598
                 $c = 0;
584 599
                 $segment = preg_replace('/'.$regex.'/', $replace, $segment, 1, $c);
585 600
 
586
-                if( $regex == array_keys($replaces)[0] && $c > 0)
587
-                    $customRegex = TRUE;
601
+                if( $regex == array_keys($replaces)[0] && $c > 0) {
602
+                                    $customRegex = TRUE;
603
+                }
588 604
             }
589 605
         }
590 606
 
@@ -602,11 +618,11 @@  discard block
 block discarded – undo
602 618
             {
603 619
                 $args['optional'][] = $arg;
604 620
                 $argConstraint = TRUE;
605
-            }
606
-            else
621
+            } else
607 622
             {
608
-                if ($argConstraint)
609
-                    show_error('Optional route path argument not valid at this position', 500, 'Route error');
623
+                if ($argConstraint) {
624
+                                    show_error('Optional route path argument not valid at this position', 500, 'Route error');
625
+                }
610 626
                 $args['required'][] = $arg;
611 627
             }
612 628
         }
@@ -721,12 +737,14 @@  discard block
 block discarded – undo
721 737
             $path = key($route);
722 738
             $_404 = $route[$path];
723 739
 
724
-            if (!isset($routes[$path]))
725
-                $routes[$path] = $_404;
740
+            if (!isset($routes[$path])) {
741
+                            $routes[$path] = $_404;
742
+            }
726 743
         }
727 744
 
728
-        if (is_null(self::$defaultController))
729
-            show_error('You must specify a home route: Route::home() as default controller!', 500, 'Route error: missing default controller');
745
+        if (is_null(self::$defaultController)) {
746
+                    show_error('You must specify a home route: Route::home() as default controller!', 500, 'Route error: missing default controller');
747
+        }
730 748
 
731 749
         $defaultController = self::$defaultController->compiled;
732 750
         $defaultController = $defaultController[key($defaultController)];
@@ -760,11 +778,13 @@  discard block
 block discarded – undo
760 778
      */
761 779
     public static function group($attr, $routes)
762 780
     {
763
-        if (!is_array($attr))
764
-            show_error('Group attribute must be a valid array');
781
+        if (!is_array($attr)) {
782
+                    show_error('Group attribute must be a valid array');
783
+        }
765 784
 
766
-        if (!isset($attr['prefix']))
767
-            show_error('You must specify an prefix!');
785
+        if (!isset($attr['prefix'])) {
786
+                    show_error('You must specify an prefix!');
787
+        }
768 788
 
769 789
         self::$prefix[] = $attr['prefix'];
770 790
 
@@ -789,16 +809,15 @@  discard block
 block discarded – undo
789 809
                 if (is_array($attr['middleware']) && !empty($attr['middleware']))
790 810
                 {
791 811
                     $mcount = count($attr['middleware']);
792
-                    foreach ($attr['middleware'] as $middleware)
793
-                        self::$middleware[] = $middleware;
794
-                }
795
-                else
812
+                    foreach ($attr['middleware'] as $middleware) {
813
+                                            self::$middleware[] = $middleware;
814
+                    }
815
+                } else
796 816
                 {
797 817
                     self::$middleware[] = $attr['middleware'];
798 818
                     $mcount = 1;
799 819
                 }
800
-            }
801
-            else
820
+            } else
802 821
             {
803 822
                 show_error('Group middleware must be an array o a string', 500, 'Route error');
804 823
             }
@@ -809,12 +828,14 @@  discard block
 block discarded – undo
809 828
         array_pop(self::$prefix);
810 829
         array_pop(self::$hideOriginals);
811 830
 
812
-        if( isset($attr['namespace']) )
813
-            array_pop(self::$namespace);
831
+        if( isset($attr['namespace']) ) {
832
+                    array_pop(self::$namespace);
833
+        }
814 834
 
815 835
         // Flushing nested middleware:
816
-        for($i = 0; $i < $mcount; $i++)
817
-            array_pop(self::$middleware);
836
+        for($i = 0; $i < $mcount; $i++) {
837
+                    array_pop(self::$middleware);
838
+        }
818 839
     }
819 840
 
820 841
 
@@ -835,14 +856,17 @@  discard block
 block discarded – undo
835 856
                 'as'   => $as
836 857
             ];
837 858
 
838
-        if (!is_null($attr) && !is_array($attr))
839
-            show_error('Default controller attributes must be an array', 500, 'Route error: bad attribute type');
859
+        if (!is_null($attr) && !is_array($attr)) {
860
+                    show_error('Default controller attributes must be an array', 500, 'Route error: bad attribute type');
861
+        }
840 862
 
841
-        if (!is_null($attr))
842
-            $routeAttr = array_merge($routeAttr, $attr);
863
+        if (!is_null($attr)) {
864
+                    $routeAttr = array_merge($routeAttr, $attr);
865
+        }
843 866
 
844
-        if (isset($attr['prefix']))
845
-            show_error('Default controller may not have a prefix!', 500, 'Route error: prefix not allowed');
867
+        if (isset($attr['prefix'])) {
868
+                    show_error('Default controller may not have a prefix!', 500, 'Route error: prefix not allowed');
869
+        }
846 870
 
847 871
         self::$defaultController = self::$routes[] = self::add('GET', '/', ['uses' => $controller, 'as' => $as], TRUE, TRUE);
848 872
     }
@@ -861,14 +885,14 @@  discard block
 block discarded – undo
861 885
         if (is_null($verb))
862 886
         {
863 887
             return self::$routes;
864
-        }
865
-        else
888
+        } else
866 889
         {
867 890
             $routes = [];
868 891
             foreach (self::$routes as $route)
869 892
             {
870
-                if ($route->verb == $verb)
871
-                    $routes[] = $route;
893
+                if ($route->verb == $verb) {
894
+                                    $routes[] = $route;
895
+                }
872 896
             }
873 897
             return $routes;
874 898
         }
@@ -965,18 +989,21 @@  discard block
 block discarded – undo
965 989
      */
966 990
     public static function getRouteByPath($path, $requestMethod = NULL)
967 991
     {
968
-        if (is_null($requestMethod))
969
-            $requestMethod = $_SERVER['REQUEST_METHOD'];
992
+        if (is_null($requestMethod)) {
993
+                    $requestMethod = $_SERVER['REQUEST_METHOD'];
994
+        }
970 995
 
971 996
         $routes = self::getRoutes($requestMethod);
972 997
 
973
-        if (empty($routes))
974
-            return FALSE;
998
+        if (empty($routes)) {
999
+                    return FALSE;
1000
+        }
975 1001
 
976 1002
         $path = trim($path);
977 1003
 
978
-        if ($path == '')
979
-            return self::$defaultController;
1004
+        if ($path == '') {
1005
+                    return self::$defaultController;
1006
+        }
980 1007
 
981 1008
         $wildcards =
982 1009
             [
@@ -1002,10 +1029,10 @@  discard block
 block discarded – undo
1002 1029
 
1003 1030
                     if ($mode == 'exact')
1004 1031
                     {
1005
-                        if ($findPath == $compiledPath)
1006
-                            return $route;
1007
-                    }
1008
-                    else
1032
+                        if ($findPath == $compiledPath) {
1033
+                                                    return $route;
1034
+                        }
1035
+                    } else
1009 1036
                     {
1010 1037
                         $e_findPath     = explode('/', $findPath);
1011 1038
                         $e_compiledPath = explode('/', $compiledPath);
@@ -1025,24 +1052,28 @@  discard block
 block discarded – undo
1025 1052
 
1026 1053
                                 $valid = (bool) preg_match('#^'.$reg.'$#', $e_findPath[$i]);
1027 1054
 
1028
-                                if ($valid && $count > 0)
1029
-                                    $skip_seg[] = $i;
1055
+                                if ($valid && $count > 0) {
1056
+                                                                    $skip_seg[] = $i;
1057
+                                }
1030 1058
                             }
1031 1059
 
1032 1060
                             if ($valid)
1033 1061
                             {
1034 1062
                                 for ($i = 0; $i < $c_e_findPath; $i++)
1035 1063
                                 {
1036
-                                    if(in_array($i, $skip_seg))
1037
-                                        continue;
1064
+                                    if(in_array($i, $skip_seg)) {
1065
+                                                                            continue;
1066
+                                    }
1038 1067
 
1039
-                                    if ($valid)
1040
-                                        $valid = $e_findPath[$i] == $e_compiledPath[$i];
1068
+                                    if ($valid) {
1069
+                                                                            $valid = $e_findPath[$i] == $e_compiledPath[$i];
1070
+                                    }
1041 1071
                                 }
1042 1072
                             }
1043 1073
 
1044
-                            if ($valid)
1045
-                                return $route;
1074
+                            if ($valid) {
1075
+                                                            return $route;
1076
+                            }
1046 1077
                         }
1047 1078
                     }
1048 1079
                 }
@@ -1076,8 +1107,9 @@  discard block
 block discarded – undo
1076 1107
 
1077 1108
         for ($s = 0; $s < count($r_seg); $s++)
1078 1109
         {
1079
-            if (!isset($p_seg[$s]))
1080
-                continue;
1110
+            if (!isset($p_seg[$s])) {
1111
+                            continue;
1112
+            }
1081 1113
 
1082 1114
             if ($r_seg[$s] != $p_seg[$s])
1083 1115
             {
Please login to merge, or discard this patch.