Completed
Push — master ( 19a002...9e523e )
by Anderson
02:02
created
src/Core/Route.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1003,7 +1003,7 @@
 block discarded – undo
1003 1003
                             {
1004 1004
                                 for ($i = 0; $i < count($e_findPath); $i++)
1005 1005
                                 {
1006
-                                    if(in_array($i, $skip_seg))
1006
+                                    if (in_array($i, $skip_seg))
1007 1007
                                         continue;
1008 1008
 
1009 1009
                                     if ($valid)
Please login to merge, or discard this patch.
Braces   +114 added lines, -86 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, '/');
@@ -589,11 +603,11 @@  discard block
 block discarded – undo
589 603
             {
590 604
                 $args['optional'][] = $arg;
591 605
                 $argConstraint = TRUE;
592
-            }
593
-            else
606
+            } else
594 607
             {
595
-                if ($argConstraint)
596
-                    show_error('Optional route path argument not valid at this position', 500, 'Route error');
608
+                if ($argConstraint) {
609
+                                    show_error('Optional route path argument not valid at this position', 500, 'Route error');
610
+                }
597 611
                 $args['required'][] = $arg;
598 612
             }
599 613
         }
@@ -703,12 +717,14 @@  discard block
 block discarded – undo
703 717
             $path = key($route);
704 718
             $_404 = $route[$path];
705 719
 
706
-            if (!isset($routes[$path]))
707
-                $routes[$path] = $_404;
720
+            if (!isset($routes[$path])) {
721
+                            $routes[$path] = $_404;
722
+            }
708 723
         }
709 724
 
710
-        if (is_null(self::$defaultController))
711
-            show_error('You must specify a home route: Route::home() as default controller!', 500, 'Route error: missing default controller');
725
+        if (is_null(self::$defaultController)) {
726
+                    show_error('You must specify a home route: Route::home() as default controller!', 500, 'Route error: missing default controller');
727
+        }
712 728
 
713 729
         $defaultController = self::$defaultController->compiled;
714 730
         $defaultController = $defaultController[key($defaultController)];
@@ -742,11 +758,13 @@  discard block
 block discarded – undo
742 758
      */
743 759
     public static function group($attr, $routes)
744 760
     {
745
-        if (!is_array($attr))
746
-            show_error('Group attribute must be a valid array');
761
+        if (!is_array($attr)) {
762
+                    show_error('Group attribute must be a valid array');
763
+        }
747 764
 
748
-        if (!isset($attr['prefix']))
749
-            show_error('You must specify an prefix!');
765
+        if (!isset($attr['prefix'])) {
766
+                    show_error('You must specify an prefix!');
767
+        }
750 768
 
751 769
         self::$prefix[] = $attr['prefix'];
752 770
 
@@ -769,15 +787,14 @@  discard block
 block discarded – undo
769 787
             {
770 788
                 if (is_array($attr['middleware']) && !empty($attr['middleware']))
771 789
                 {
772
-                    foreach ($attr['middleware'] as $middleware)
773
-                        self::$middleware[] = $middleware;
774
-                }
775
-                else
790
+                    foreach ($attr['middleware'] as $middleware) {
791
+                                            self::$middleware[] = $middleware;
792
+                    }
793
+                } else
776 794
                 {
777 795
                     self::$middleware[] = $attr['middleware'];
778 796
                 }
779
-            }
780
-            else
797
+            } else
781 798
             {
782 799
                 show_error('Group middleware must be an array o a string', 500, 'Route error');
783 800
             }
@@ -809,14 +826,17 @@  discard block
 block discarded – undo
809 826
                 'as'   => $as
810 827
             ];
811 828
 
812
-        if (!is_null($attr) && !is_array($attr))
813
-            show_error('Default controller attributes must be an array', 500, 'Route error: bad attribute type');
829
+        if (!is_null($attr) && !is_array($attr)) {
830
+                    show_error('Default controller attributes must be an array', 500, 'Route error: bad attribute type');
831
+        }
814 832
 
815
-        if (!is_null($attr))
816
-            $routeAttr = array_merge($routeAttr, $attr);
833
+        if (!is_null($attr)) {
834
+                    $routeAttr = array_merge($routeAttr, $attr);
835
+        }
817 836
 
818
-        if (isset($attr['prefix']))
819
-            show_error('Default controller may not have a prefix!', 500, 'Route error: prefix not allowed');
837
+        if (isset($attr['prefix'])) {
838
+                    show_error('Default controller may not have a prefix!', 500, 'Route error: prefix not allowed');
839
+        }
820 840
 
821 841
         self::$defaultController = self::$routes[] = self::add('GET', '/', ['uses' => $controller, 'as' => $as], TRUE, TRUE);
822 842
     }
@@ -835,14 +855,14 @@  discard block
 block discarded – undo
835 855
         if (is_null($verb))
836 856
         {
837 857
             return self::$routes;
838
-        }
839
-        else
858
+        } else
840 859
         {
841 860
             $routes = [];
842 861
             foreach (self::$routes as $route)
843 862
             {
844
-                if ($route->verb == $verb)
845
-                    $routes[] = $route;
863
+                if ($route->verb == $verb) {
864
+                                    $routes[] = $route;
865
+                }
846 866
             }
847 867
             return $routes;
848 868
         }
@@ -939,18 +959,21 @@  discard block
 block discarded – undo
939 959
      */
940 960
     public static function getRouteByPath($path, $requestMethod = NULL)
941 961
     {
942
-        if (is_null($requestMethod))
943
-            $requestMethod = $_SERVER['REQUEST_METHOD'];
962
+        if (is_null($requestMethod)) {
963
+                    $requestMethod = $_SERVER['REQUEST_METHOD'];
964
+        }
944 965
 
945 966
         $routes = self::getRoutes($requestMethod);
946 967
 
947
-        if (empty($routes))
948
-            return FALSE;
968
+        if (empty($routes)) {
969
+                    return FALSE;
970
+        }
949 971
 
950 972
         $path = trim($path);
951 973
 
952
-        if ($path == '')
953
-            return self::$defaultController;
974
+        if ($path == '') {
975
+                    return self::$defaultController;
976
+        }
954 977
 
955 978
         $wildcards =
956 979
             [
@@ -976,10 +999,10 @@  discard block
 block discarded – undo
976 999
 
977 1000
                     if ($mode == 'exact')
978 1001
                     {
979
-                        if ($findPath == $compiledPath)
980
-                            return $route;
981
-                    }
982
-                    else
1002
+                        if ($findPath == $compiledPath) {
1003
+                                                    return $route;
1004
+                        }
1005
+                    } else
983 1006
                     {
984 1007
                         $e_findPath     = explode('/', $findPath);
985 1008
                         $e_compiledPath = explode('/', $compiledPath);
@@ -995,24 +1018,28 @@  discard block
 block discarded – undo
995 1018
                                 $reg   = preg_replace($wildcards, $replaces, $e_compiledPath[$i], -1, $count);
996 1019
                                 $valid = (bool) preg_match('#^'.$reg.'$#', $e_findPath[$i]);
997 1020
 
998
-                                if ($valid && $count > 0)
999
-                                    $skip_seg[] = $i;
1021
+                                if ($valid && $count > 0) {
1022
+                                                                    $skip_seg[] = $i;
1023
+                                }
1000 1024
                             }
1001 1025
 
1002 1026
                             if ($valid)
1003 1027
                             {
1004 1028
                                 for ($i = 0; $i < count($e_findPath); $i++)
1005 1029
                                 {
1006
-                                    if(in_array($i, $skip_seg))
1007
-                                        continue;
1030
+                                    if(in_array($i, $skip_seg)) {
1031
+                                                                            continue;
1032
+                                    }
1008 1033
 
1009
-                                    if ($valid)
1010
-                                        $valid = $e_findPath[$i] == $e_compiledPath[$i];
1034
+                                    if ($valid) {
1035
+                                                                            $valid = $e_findPath[$i] == $e_compiledPath[$i];
1036
+                                    }
1011 1037
                                 }
1012 1038
                             }
1013 1039
 
1014
-                            if ($valid)
1015
-                                return $route;
1040
+                            if ($valid) {
1041
+                                                            return $route;
1042
+                            }
1016 1043
                         }
1017 1044
                     }
1018 1045
                 }
@@ -1046,8 +1073,9 @@  discard block
 block discarded – undo
1046 1073
 
1047 1074
         for ($s = 0; $s < count($r_seg); $s++)
1048 1075
         {
1049
-            if (!isset($p_seg[$s]))
1050
-                continue;
1076
+            if (!isset($p_seg[$s])) {
1077
+                            continue;
1078
+            }
1051 1079
 
1052 1080
             if ($r_seg[$s] != $p_seg[$s])
1053 1081
             {
Please login to merge, or discard this patch.