Completed
Branch master (9056d3)
by Anderson
01:57
created
src/Middleware/Request.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -65,19 +65,19 @@  discard block
 block discarded – undo
65 65
 
66 66
         // FIXME: Solve ambiguity here! POST with _method="GET" makes no sense
67 67
 
68
-        if(isset($_POST['_method']) && in_array(strtoupper($_POST['_method']), $validMethods , TRUE))
68
+        if (isset($_POST['_method']) && in_array(strtoupper($_POST['_method']), $validMethods, TRUE))
69 69
             $formMethod = strtoupper($_POST['_method']);
70 70
 
71
-        if(is_null($formMethod))
71
+        if (is_null($formMethod))
72 72
         {
73 73
             $this->requestMethod = $requestMethod;
74 74
         }
75 75
         else
76 76
         {
77
-            if($requestMethod == 'POST')
77
+            if ($requestMethod == 'POST')
78 78
                 $this->requestMethod = $formMethod;
79 79
 
80
-            if(!$this->CI->input->is_ajax_request() && $this->requestMethod == 'HEAD')
80
+            if (!$this->CI->input->is_ajax_request() && $this->requestMethod == 'HEAD')
81 81
                 $this->requestMethod = 'POST';
82 82
         }
83 83
     }
@@ -91,9 +91,9 @@  discard block
 block discarded – undo
91 91
      */
92 92
     public function run()
93 93
     {
94
-        if(!$this->route)
94
+        if (!$this->route)
95 95
         {
96
-            if(ENVIRONMENT != 'production')
96
+            if (ENVIRONMENT != 'production')
97 97
             {
98 98
                 show_error('The request method '.$this->requestMethod.' is not allowed to view the resource', 403, 'Forbidden method');
99 99
             }
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
             }
104 104
         }
105 105
 
106
-        if(method_exists($this->CI,$this->route->method))
106
+        if (method_exists($this->CI, $this->route->method))
107 107
         {
108 108
             $this->CI->{$this->route->method}();
109 109
 
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
         }
115 115
         else
116 116
         {
117
-            if(ENVIRONMENT != 'production')
117
+            if (ENVIRONMENT != 'production')
118 118
             {
119 119
                 show_error('The method '.$this->route->controller.'::'.$this->route->method.'() does not exists', 500, 'Method not found');
120 120
             }
Please login to merge, or discard this patch.
src/Core/Middleware.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      */
52 52
     public function __construct()
53 53
     {
54
-        $this->CI =& self::$instance;
54
+        $this->CI = & self::$instance;
55 55
     }
56 56
 
57 57
     /**
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
      */
65 65
     public static function init()
66 66
     {
67
-        self::$instance =& get_instance();
67
+        self::$instance = & get_instance();
68 68
         self::$uri_string = self::$instance->router->uri->uri_string();
69 69
 
70 70
         // Execute user defined middleware:
@@ -94,34 +94,34 @@  discard block
 block discarded – undo
94 94
         $_run = array();
95 95
 
96 96
         // Current route middleware
97
-        if($currentRoute !== FALSE)
97
+        if ($currentRoute !== FALSE)
98 98
         {
99
-            foreach($currentRoute->middleware as $middleware)
99
+            foreach ($currentRoute->middleware as $middleware)
100 100
             {
101
-                if(!in_array($middleware,$_run))
101
+                if (!in_array($middleware, $_run))
102 102
                     $_run[] = $middleware;
103 103
             }
104 104
         }
105 105
 
106 106
         // Group middleware:
107
-        foreach($groupMiddleware as $middlewares)
107
+        foreach ($groupMiddleware as $middlewares)
108 108
         {
109
-            foreach($middlewares as $path => $middleware)
109
+            foreach ($middlewares as $path => $middleware)
110 110
             {
111 111
                 $_lenght = strlen($path);
112 112
 
113 113
                 $search = self::$uri_string;
114
-                $search = substr($search,0,$_lenght);
114
+                $search = substr($search, 0, $_lenght);
115 115
 
116
-                if( $search === $path )
116
+                if ($search === $path)
117 117
                 {
118
-                    if(!in_array($middleware,$_run))
118
+                    if (!in_array($middleware, $_run))
119 119
                          $_run[] = $middleware;
120 120
                 }
121 121
             }
122 122
         }
123 123
 
124
-        foreach($_run as $middleware)
124
+        foreach ($_run as $middleware)
125 125
         {
126 126
             self::runMiddleware($middleware);
127 127
         }
@@ -145,30 +145,30 @@  discard block
 block discarded – undo
145 145
 
146 146
         $middlewareName = ucfirst($middlewareName).'_middleware';
147 147
 
148
-        if(!file_exists($middlewareDir))
148
+        if (!file_exists($middlewareDir))
149 149
             show_error('Unable to find (or read) the middleware folder: "'.$middlewareDir.'"');
150 150
 
151
-        $runMiddleware =  $middlewareDir.$middlewareName.'.php';
151
+        $runMiddleware = $middlewareDir.$middlewareName.'.php';
152 152
 
153
-        if(!file_exists($runMiddleware))
153
+        if (!file_exists($runMiddleware))
154 154
             show_error('Unable to find (or read) the middleware "'.$runMiddleware.'"');
155 155
 
156 156
         require $runMiddleware;
157 157
 
158
-        if(!class_exists($middlewareName))
158
+        if (!class_exists($middlewareName))
159 159
             show_error('Class "'.$middlewareName.'" not found');
160 160
 
161 161
         $middleware = new $middlewareName();
162 162
 
163 163
         // Call the current controller __beforeMiddleware() method, if exists:
164
-        if(method_exists(self::$instance, '_beforeMiddleware'))
164
+        if (method_exists(self::$instance, '_beforeMiddleware'))
165 165
             self::$instance->_beforeMiddleware();
166 166
 
167 167
         // Run the middleware
168 168
         $middleware->run();
169 169
 
170 170
         // Call the current controller _afterMiddleware() method, if exists:
171
-        if(method_exists(self::$instance, '_afterMiddleware'))
171
+        if (method_exists(self::$instance, '_afterMiddleware'))
172 172
             self::$instance->_afterMiddleware();
173 173
 
174 174
     }
Please login to merge, or discard this patch.
src/Core/Route.php 1 patch
Spacing   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -131,17 +131,17 @@  discard block
 block discarded – undo
131 131
      */
132 132
     public static function add($verb, $path, $attr, $hideOriginal = TRUE, $return = FALSE)
133 133
     {
134
-        if(!is_array($attr))
134
+        if (!is_array($attr))
135 135
         {
136
-            show_error('You must specify the route attributes as an array',500,'Route error: bad attributes');
136
+            show_error('You must specify the route attributes as an array', 500, 'Route error: bad attributes');
137 137
         }
138 138
 
139
-        if(!isset($attr['uses']))
139
+        if (!isset($attr['uses']))
140 140
         {
141 141
             show_error('Route requires a \'controller@method\' to be pointed and it\'s not defined in the route attributes', 500, 'Route error: missing controller');
142 142
         }
143 143
 
144
-        if(!preg_match('/^([a-zA-Z1-9-_]+)@([a-zA-Z1-9-_]+)$/', $attr['uses'], $parsedController) !== FALSE)
144
+        if (!preg_match('/^([a-zA-Z1-9-_]+)@([a-zA-Z1-9-_]+)$/', $attr['uses'], $parsedController) !== FALSE)
145 145
         {
146 146
             show_error('Route controller must be in format controller@method', 500, 'Route error: bad controller format');
147 147
         }
@@ -149,28 +149,28 @@  discard block
 block discarded – undo
149 149
         $controller = $parsedController[1];
150 150
         $method     = $parsedController[2];
151 151
 
152
-        if(!is_string($path))
152
+        if (!is_string($path))
153 153
             show_error('Route path must be a string ', 500, 'Route error: bad route path');
154 154
 
155
-        if(!is_string($verb))
155
+        if (!is_string($verb))
156 156
             show_error('Route HTTP Verb must be a string', 500, 'Route error: bad verb type');
157 157
 
158 158
         $verb = strtoupper($verb);
159 159
 
160
-        if(!in_array($verb, self::$http_verbs,TRUE))
160
+        if (!in_array($verb, self::$http_verbs, TRUE))
161 161
         {
162 162
             $errorMsg = 'Verb "'.$verb.'" is not a valid HTTP Verb, allowed verbs:<ul>';
163
-            foreach( self::$http_verbs as $validVerb )
163
+            foreach (self::$http_verbs as $validVerb)
164 164
             {
165 165
                 $errorMsg .= '<li>'.$validVerb.'</li>';
166 166
             }
167 167
             $errorMsg .= '</ul>';
168
-            show_error($errorMsg,500,'Route error: unknow method');
168
+            show_error($errorMsg, 500, 'Route error: unknow method');
169 169
         }
170 170
 
171 171
         $route['verb'] = $verb;
172 172
 
173
-        $path = trim($path,'/');
173
+        $path = trim($path, '/');
174 174
 
175 175
         //if($path == '')
176 176
         //    $path = '/';
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
         $route['controller'] = $controller;
180 180
         $route['method']     = $method;
181 181
 
182
-        if(isset($attr['as']))
182
+        if (isset($attr['as']))
183 183
         {
184 184
             $route['name'] = $attr['as'];
185 185
         }
@@ -190,48 +190,48 @@  discard block
 block discarded – undo
190 190
 
191 191
         $route['prefix'] = NULL;
192 192
 
193
-        if(!is_null(self::$prefix))
194
-            $route['prefix'] = self::$prefix;   # Group
195
-        if(isset($attr['prefix']))
193
+        if (!is_null(self::$prefix))
194
+            $route['prefix'] = self::$prefix; # Group
195
+        if (isset($attr['prefix']))
196 196
             $route['prefix'] = $attr['prefix']; # Specific (will overwrite group prefix)
197 197
 
198 198
         $route['namespace'] = NULL;
199 199
 
200
-        if(!is_null(self::$namespace))
201
-            $route['namespace'] = self::$namespace;   # Group
202
-        if(isset($attr['namespace']))
200
+        if (!is_null(self::$namespace))
201
+            $route['namespace'] = self::$namespace; # Group
202
+        if (isset($attr['namespace']))
203 203
             $route['namespace'] = $attr['namespace']; # Specific (will overwrite group namespace)
204 204
 
205 205
         # Removing trailing slashes
206
-        if(!is_null($route['prefix']))
206
+        if (!is_null($route['prefix']))
207 207
         {
208
-            $route['prefix'] = trim($route['prefix'],'/');
209
-            if($route['prefix'] == '')
208
+            $route['prefix'] = trim($route['prefix'], '/');
209
+            if ($route['prefix'] == '')
210 210
                 $route['prefix'] = NULL;
211 211
         }
212
-        if(!is_null($route['namespace']))
212
+        if (!is_null($route['namespace']))
213 213
         {
214
-            $route['namespace'] = trim($route['namespace'],'/');
215
-            if($route['namespace'] == '')
214
+            $route['namespace'] = trim($route['namespace'], '/');
215
+            if ($route['namespace'] == '')
216 216
                 $route['namespace'] = NULL;
217 217
         }
218 218
 
219 219
         $route['middleware'] = array();
220 220
 
221
-        if(isset($attr['middleware']))
221
+        if (isset($attr['middleware']))
222 222
         {
223
-            if(is_array($attr['middleware']))
223
+            if (is_array($attr['middleware']))
224 224
             {
225
-                foreach($attr['middleware'] as $middleware)
225
+                foreach ($attr['middleware'] as $middleware)
226 226
                     $route['middleware'][] = $middleware; # Group
227 227
             }
228
-            elseif( is_string($attr['middleware']))
228
+            elseif (is_string($attr['middleware']))
229 229
             {
230 230
                 $route['middleware'][] = $attr['middleware']; # Group
231 231
             }
232 232
             else
233 233
             {
234
-                show_error('Route middleware must be a string or an array',500,'Route error: bad middleware format');
234
+                show_error('Route middleware must be a string or an array', 500, 'Route error: bad middleware format');
235 235
             }
236 236
         }
237 237
 
@@ -241,27 +241,27 @@  discard block
 block discarded – undo
241 241
             $compiledRoute->path => $compiledRoute->route
242 242
         ];
243 243
 
244
-        if($hideOriginal || self::$hideOriginals === TRUE || ($compiledRoute->path != '' && $compiledRoute->path != '/' ) )
244
+        if ($hideOriginal || self::$hideOriginals === TRUE || ($compiledRoute->path != '' && $compiledRoute->path != '/'))
245 245
         {
246 246
             $hiddenRoutePath      = $controller.'/'.$method;
247 247
             $hiddenRouteNamespace = '';
248 248
 
249
-            if(!is_null($route['namespace']))
249
+            if (!is_null($route['namespace']))
250 250
             {
251 251
                 $hiddenRouteNamespace = $route['namespace'].'/';
252 252
             }
253 253
 
254 254
             $hiddenRoutePath = $hiddenRouteNamespace.$hiddenRoutePath;
255 255
 
256
-            if($method == 'index')
256
+            if ($method == 'index')
257 257
             {
258
-                self::$hiddenRoutes[] = [ $hiddenRouteNamespace.$controller  => function(){ show_404(); }];
258
+                self::$hiddenRoutes[] = [$hiddenRouteNamespace.$controller  => function() { show_404(); }];
259 259
             }
260 260
 
261
-            self::$hiddenRoutes[] = [$hiddenRoutePath => function(){ show_404(); }];
261
+            self::$hiddenRoutes[] = [$hiddenRoutePath => function() { show_404(); }];
262 262
         }
263 263
 
264
-        if(!$return)
264
+        if (!$return)
265 265
         {
266 266
             self::$routes[] = (object) $route;
267 267
         }
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
      */
286 286
     public static function get($url, $attr, $hideOriginal = TRUE)
287 287
     {
288
-        self::add('GET', $url,$attr, $hideOriginal);
288
+        self::add('GET', $url, $attr, $hideOriginal);
289 289
     }
290 290
 
291 291
     /**
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
      */
303 303
     public static function post($url, $attr, $hideOriginal = TRUE)
304 304
     {
305
-        self::add('POST', $url,$attr, $hideOriginal);
305
+        self::add('POST', $url, $attr, $hideOriginal);
306 306
     }
307 307
 
308 308
     /**
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
      */
320 320
     public static function put($url, $attr, $hideOriginal = TRUE)
321 321
     {
322
-        self::add('PUT', $url,$attr, $hideOriginal);
322
+        self::add('PUT', $url, $attr, $hideOriginal);
323 323
     }
324 324
 
325 325
     /**
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
      */
337 337
     public static function patch($url, $attr, $hideOriginal = TRUE)
338 338
     {
339
-        self::add('PATCH', $url,$attr, $hideOriginal);
339
+        self::add('PATCH', $url, $attr, $hideOriginal);
340 340
     }
341 341
 
342 342
     /**
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
      */
354 354
     public static function delete($url, $attr, $hideOriginal = TRUE)
355 355
     {
356
-        self::add('DELETE', $url,$attr, $hideOriginal);
356
+        self::add('DELETE', $url, $attr, $hideOriginal);
357 357
     }
358 358
 
359 359
     /**
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
      */
371 371
     public static function any($url, $attr, $hideOriginal = TRUE)
372 372
     {
373
-        foreach(self::$http_verbs as $verb)
373
+        foreach (self::$http_verbs as $verb)
374 374
         {
375 375
             $verb = strtolower($verb);
376 376
             self::add($verb, $url, $attr, $hideOriginal);
@@ -392,10 +392,10 @@  discard block
 block discarded – undo
392 392
      */
393 393
     public static function matches($verbs, $url, $attr, $hideOriginal = FALSE)
394 394
     {
395
-        if(!is_array($verbs))
395
+        if (!is_array($verbs))
396 396
             show_error('Route::matches() first argument must be an array of valid HTTP Verbs', 500, 'Route error: bad Route::matches() verb list');
397 397
 
398
-        foreach($verbs as $verb)
398
+        foreach ($verbs as $verb)
399 399
         {
400 400
             self::add($verb, $url, $attr, $hideOriginal);
401 401
         }
@@ -430,25 +430,25 @@  discard block
 block discarded – undo
430 430
 
431 431
         $hideOriginal = FALSE;
432 432
 
433
-        if(isset($attr['namespace']))
433
+        if (isset($attr['namespace']))
434 434
             $base_attr['namespace']  = $attr['namespace'];
435 435
 
436
-        if(isset($attr['middleware']))
436
+        if (isset($attr['middleware']))
437 437
             $base_attr['middleware'] = $attr['middleware'];
438 438
 
439
-        if(isset($attr['hideOriginal']))
439
+        if (isset($attr['hideOriginal']))
440 440
             $hideOriginal = (bool) $attr['hideOriginal'];
441 441
 
442
-        if(isset($attr['prefix']))
443
-            $base_attr['prefix']  = $attr['prefix'];
442
+        if (isset($attr['prefix']))
443
+            $base_attr['prefix'] = $attr['prefix'];
444 444
 
445 445
         $only = array();
446 446
 
447
-        if(isset($attr['only']) && (is_array($attr['only']) || is_string($attr['only'])))
447
+        if (isset($attr['only']) && (is_array($attr['only']) || is_string($attr['only'])))
448 448
         {
449
-            if(is_array($attr['only']))
449
+            if (is_array($attr['only']))
450 450
             {
451
-                $only  = strtolower($attr['only']);
451
+                $only = strtolower($attr['only']);
452 452
             }
453 453
             else
454 454
             {
@@ -456,43 +456,43 @@  discard block
 block discarded – undo
456 456
             }
457 457
         }
458 458
 
459
-        if(empty($only) || in_array('index', $only))
459
+        if (empty($only) || in_array('index', $only))
460 460
         {
461
-            $route_attr = array_merge($base_attr, ['uses' => $controller.'@index',   'as' => $name.'.index']);
461
+            $route_attr = array_merge($base_attr, ['uses' => $controller.'@index', 'as' => $name.'.index']);
462 462
             self::get('/', $route_attr, $hideOriginal);
463 463
         }
464 464
 
465
-        if(empty($only) || in_array('create', $only))
465
+        if (empty($only) || in_array('create', $only))
466 466
         {
467 467
             $route_attr = array_merge($base_attr, ['uses' => $controller.'@create', 'as' => $name.'.create']);
468 468
             self::get('create', $route_attr, $hideOriginal);
469 469
         }
470 470
 
471
-        if(empty($only) || in_array('store', $only))
471
+        if (empty($only) || in_array('store', $only))
472 472
         {
473 473
             $route_attr = array_merge($base_attr, ['uses' => $controller.'@store', 'as' => $name.'.store']);
474 474
             self::post('/', $route_attr, $hideOriginal);
475 475
         }
476 476
 
477
-        if(empty($only) || in_array('show', $only))
477
+        if (empty($only) || in_array('show', $only))
478 478
         {
479 479
             $route_attr = array_merge($base_attr, ['uses' => $controller.'@show', 'as' => $name.'.show']);
480 480
             self::get('{slug}', $route_attr, $hideOriginal);
481 481
         }
482 482
 
483
-        if(empty($only) || in_array('edit', $only))
483
+        if (empty($only) || in_array('edit', $only))
484 484
         {
485 485
             $route_attr = array_merge($base_attr, ['uses' => $controller.'@edit', 'as' => $name.'.edit']);
486 486
             self::get('{slug}/edit', $route_attr, $hideOriginal);
487 487
         }
488 488
 
489
-        if(empty($only) || in_array('update', $only))
489
+        if (empty($only) || in_array('update', $only))
490 490
         {
491 491
             $route_attr = array_merge($base_attr, ['uses' => $controller.'@update', 'as' => $name.'.update']);
492 492
             self::matches(['PUT', 'PATCH'], '{slug}/update', $route_attr, $hideOriginal);
493 493
         }
494 494
 
495
-        if(empty($only) || in_array('destroy', $only))
495
+        if (empty($only) || in_array('destroy', $only))
496 496
         {
497 497
             $route_attr = array_merge($base_attr, ['uses' => $controller.'@destroy', 'as' => $name.'.destroy']);
498 498
             self::delete('{slug}', $route_attr, $hideOriginal);
@@ -514,32 +514,32 @@  discard block
 block discarded – undo
514 514
         $prefix    = NULL;
515 515
         $namespace = NULL;
516 516
 
517
-        if(!is_null($route->prefix))
517
+        if (!is_null($route->prefix))
518 518
         {
519 519
             $prefix = $route->prefix;
520 520
         }
521 521
 
522
-        if(!is_null($route->namespace))
522
+        if (!is_null($route->namespace))
523 523
         {
524 524
             $namespace = $route->namespace;
525 525
         }
526 526
 
527 527
         $path = $route->path;
528 528
 
529
-        if(!is_null($prefix))
529
+        if (!is_null($prefix))
530 530
             $path = $prefix.'/'.$path;
531 531
 
532
-        if(substr($path, 0, 1) == "/" && strlen($path) > 1)
533
-            $path = substr($path,1);
532
+        if (substr($path, 0, 1) == "/" && strlen($path) > 1)
533
+            $path = substr($path, 1);
534 534
 
535 535
         $controller = $route->controller.'/'.$route->method;
536 536
 
537
-        if(!is_null($namespace))
537
+        if (!is_null($namespace))
538 538
             $controller = $namespace.'/'.$controller;
539 539
 
540 540
         $replaces =
541 541
             [
542
-                '{\((.*)\):[a-zA-Z0-9-_]*}' => '($1)',   # Custom regular expression
542
+                '{\((.*)\):[a-zA-Z0-9-_]*}' => '($1)', # Custom regular expression
543 543
                 '{num:[a-zA-Z0-9-_]*}'      => '(:num)', # (:num) route
544 544
                 '{any:[a-zA-Z0-9-_]*}'      => '(:any)', # (:any) route
545 545
                 '{[a-zA-Z0-9-_]*}'          => '(:any)', # Everything else
@@ -547,23 +547,23 @@  discard block
 block discarded – undo
547 547
 
548 548
         $argCount = 0;
549 549
 
550
-        foreach($replaces as $regex => $replace)
550
+        foreach ($replaces as $regex => $replace)
551 551
         {
552 552
             $path = preg_replace('/'.$regex.'/', $replace, $path, -1, $argCount);
553 553
         }
554 554
 
555
-        if($argCount > 0)
555
+        if ($argCount > 0)
556 556
         {
557
-            for($i = 0; $i < $argCount; $i++)
557
+            for ($i = 0; $i < $argCount; $i++)
558 558
             {
559 559
                 $controller .= '/$'.($i + 1);
560 560
             }
561 561
         }
562 562
 
563 563
         // Removing trailing slash (it causes 404 even if the route exists, I don't know why)
564
-        if(substr($path,-1) == '/')
564
+        if (substr($path, -1) == '/')
565 565
         {
566
-            $path = substr($path,0,-1);
566
+            $path = substr($path, 0, -1);
567 567
         }
568 568
 
569 569
         return (object) [
@@ -584,11 +584,11 @@  discard block
 block discarded – undo
584 584
     {
585 585
         $routes = array();
586 586
 
587
-        foreach(self::$routes as $index => $route)
587
+        foreach (self::$routes as $index => $route)
588 588
         {
589 589
             $compiled = self::compileRoute($route);
590 590
 
591
-            if( !isset($routes[$compiled->path]) || $route->verb == 'GET' )
591
+            if (!isset($routes[$compiled->path]) || $route->verb == 'GET')
592 592
             {
593 593
                 $routes[$compiled->path] = $compiled->route;
594 594
             }
@@ -596,16 +596,16 @@  discard block
 block discarded – undo
596 596
             self::$routes[$index] = (object) $route;
597 597
         }
598 598
 
599
-        foreach(self::$hiddenRoutes as $route)
599
+        foreach (self::$hiddenRoutes as $route)
600 600
         {
601 601
             $path = key($route);
602 602
             $_404 = $route[$path];
603 603
 
604
-            if(!isset($routes[$path]))
604
+            if (!isset($routes[$path]))
605 605
                 $routes[$path] = $_404;
606 606
         }
607 607
 
608
-        if(is_null(self::$defaultController))
608
+        if (is_null(self::$defaultController))
609 609
             show_error('You must specify a home route: Route::home() as default controller!', 500, 'Route error: missing default controller');
610 610
 
611 611
         $defaultController = self::$defaultController->compiled;
@@ -632,20 +632,20 @@  discard block
 block discarded – undo
632 632
      */
633 633
     public static function group($attr, $routes)
634 634
     {
635
-        if(!is_array($attr))
635
+        if (!is_array($attr))
636 636
             show_error('Group attribute must be a valid array');
637 637
 
638
-        if(!isset($attr['prefix']))
638
+        if (!isset($attr['prefix']))
639 639
             show_error('You must specify an prefix!');
640 640
 
641 641
         self::$prefix = $attr['prefix'];
642 642
 
643
-        if(isset($attr['namespace']))
643
+        if (isset($attr['namespace']))
644 644
         {
645 645
             self::$namespace = $attr['namespace'];
646 646
         }
647 647
 
648
-        if(isset($attr['hideOriginals']) && $attr['hideOriginals'] === TRUE)
648
+        if (isset($attr['hideOriginals']) && $attr['hideOriginals'] === TRUE)
649 649
         {
650 650
             self::$hideOriginals = TRUE;
651 651
         }
@@ -654,19 +654,19 @@  discard block
 block discarded – undo
654 654
             self::$hideOriginals = FALSE;
655 655
         }
656 656
 
657
-        if(isset($attr['middleware']))
657
+        if (isset($attr['middleware']))
658 658
         {
659
-            if(is_array($attr['middleware']) || is_string($attr['middleware']))
659
+            if (is_array($attr['middleware']) || is_string($attr['middleware']))
660 660
             {
661 661
                 //self::$middleware = $attr['middleware'];
662
-                if(is_array($attr['middleware']) && !empty($attr['middleware']))
662
+                if (is_array($attr['middleware']) && !empty($attr['middleware']))
663 663
                 {
664
-                    foreach($attr['middleware'] as $middleware)
665
-                        self::$groupMiddleware[] = [ $attr['prefix'] => $middleware ];
664
+                    foreach ($attr['middleware'] as $middleware)
665
+                        self::$groupMiddleware[] = [$attr['prefix'] => $middleware];
666 666
                 }
667 667
                 else
668 668
                 {
669
-                    self::$groupMiddleware[] = [ $attr['prefix'] => $attr['middleware'] ];
669
+                    self::$groupMiddleware[] = [$attr['prefix'] => $attr['middleware']];
670 670
                 }
671 671
             }
672 672
             else
@@ -677,17 +677,17 @@  discard block
 block discarded – undo
677 677
 
678 678
         # Special workarround for default group controller:
679 679
         # Probably i'll remove it.
680
-        if(isset($attr['default']))
680
+        if (isset($attr['default']))
681 681
         {
682 682
             $url = str_ireplace('@', '/', $attr['default']);
683
-            $uri = explode('/',$attr['default']);
683
+            $uri = explode('/', $attr['default']);
684 684
             $controller = $uri[0];
685 685
             $method = isset($uri[1]) ? $uri[1] : NULL;
686 686
 
687
-            if(self::$hideOriginals === TRUE)
688
-                self::$hiddenRoutes[] = [$controller => function(){ show_404(); }];
687
+            if (self::$hideOriginals === TRUE)
688
+                self::$hiddenRoutes[] = [$controller => function() { show_404(); }];
689 689
 
690
-            $route_attr['uses'] = $controller.( !is_null($method) ? '/'.$method : '');
690
+            $route_attr['uses'] = $controller.(!is_null($method) ? '/'.$method : '');
691 691
             self::get('/', $route_attr);
692 692
         }
693 693
 
@@ -720,16 +720,16 @@  discard block
 block discarded – undo
720 720
                 'as'   => $as
721 721
             ];
722 722
 
723
-        if(!is_null($attr) && !is_array($attr))
724
-            show_error('Default controller attributes must be an array',500,'Route error: bad attribute type');
723
+        if (!is_null($attr) && !is_array($attr))
724
+            show_error('Default controller attributes must be an array', 500, 'Route error: bad attribute type');
725 725
 
726
-        if(!is_null($attr))
727
-            $routeAttr = array_merge($routeAttr,$attr);
726
+        if (!is_null($attr))
727
+            $routeAttr = array_merge($routeAttr, $attr);
728 728
 
729
-        if(isset($attr['prefix']))
730
-            show_error('Default controller may not have a prefix!',500,'Route error: prefix not allowed');
729
+        if (isset($attr['prefix']))
730
+            show_error('Default controller may not have a prefix!', 500, 'Route error: prefix not allowed');
731 731
 
732
-        self::$defaultController = self::$routes[] = self::add('GET', '/', ['uses' => $controller, 'as' => $as],TRUE, TRUE);
732
+        self::$defaultController = self::$routes[] = self::add('GET', '/', ['uses' => $controller, 'as' => $as], TRUE, TRUE);
733 733
     }
734 734
 
735 735
     /**
@@ -747,14 +747,14 @@  discard block
 block discarded – undo
747 747
         $baseAttr['prefix']     = 'auth';
748 748
         $baseAttr['middleware'] = 'Auth';
749 749
 
750
-        if(!is_null($attr) && is_array($attr))
750
+        if (!is_null($attr) && is_array($attr))
751 751
         {
752 752
             $baseAttr = array_merge($baseAttr, $attr);
753 753
         }
754 754
 
755 755
         self::group($baseAttr, function() use($controller)
756 756
         {
757
-            self::matches(['get','post'], '/login',  ['uses' => $controller.'@login',  'as' => $controller.'.login']);
757
+            self::matches(['get', 'post'], '/login', ['uses' => $controller.'@login', 'as' => $controller.'.login']);
758 758
             self::get('/logout', ['uses' => $controller.'@logout', 'as' => $controller.'.logout']);
759 759
         });
760 760
     }
@@ -815,9 +815,9 @@  discard block
 block discarded – undo
815 815
      */
816 816
     public static function getRouteByName($search, $args = NULL)
817 817
     {
818
-        foreach(self::$routes as $route)
818
+        foreach (self::$routes as $route)
819 819
         {
820
-            if($route->name == $search)
820
+            if ($route->name == $search)
821 821
                 return base_url(self::compileRoute($route)->path);
822 822
         }
823 823
 
@@ -836,18 +836,18 @@  discard block
 block discarded – undo
836 836
     {
837 837
         $routes = array();
838 838
 
839
-        foreach(self::$routes as $route)
839
+        foreach (self::$routes as $route)
840 840
         {
841 841
             $routes[$route->verb][] = $route;
842 842
         }
843 843
 
844
-        if(empty($routes))
844
+        if (empty($routes))
845 845
             return FALSE;
846 846
 
847
-        if(is_null($requestMethod))
847
+        if (is_null($requestMethod))
848 848
             $requestMethod = $_SERVER['REQUEST_METHOD'];
849 849
 
850
-        if(!isset($routes[$requestMethod]))
850
+        if (!isset($routes[$requestMethod]))
851 851
             return FALSE;
852 852
 
853 853
         $routes = $routes[$requestMethod];
@@ -857,18 +857,18 @@  discard block
 block discarded – undo
857 857
 
858 858
         $path = trim($path);
859 859
 
860
-        if($path == '')
860
+        if ($path == '')
861 861
         {
862 862
             return self::$defaultController;
863 863
         }
864 864
 
865
-        foreach( [$path, $path.'/index'] as $findPath )
865
+        foreach ([$path, $path.'/index'] as $findPath)
866 866
         {
867
-            foreach($routes as $route)
867
+            foreach ($routes as $route)
868 868
             {
869 869
                 $compiled = $route->compiled;
870 870
 
871
-                if($findPath == key($compiled))
871
+                if ($findPath == key($compiled))
872 872
                     return $route;
873 873
             }
874 874
         }
Please login to merge, or discard this patch.