Completed
Branch master (9056d3)
by Anderson
01:57
created
src/Core/Route.php 3 patches
Doc Comments   +9 added lines, -14 removed lines patch added patch discarded remove patch
@@ -120,7 +120,6 @@  discard block
 block discarded – undo
120 120
      * Generic method to add a improved route
121 121
      *
122 122
      * @param  mixed $verb String or array of string of valid HTTP Verbs that will be accepted in this route
123
-     * @param  mixed $url String or array of strings that will trigger this route
124 123
      * @param  array $attr Associative array of route attributes
125 124
      * @param  bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside
126 125
      *
@@ -274,7 +273,7 @@  discard block
 block discarded – undo
274 273
     /**
275 274
      * Adds a GET route, alias of Route::add('GET',$url,$attr,$hideOriginal)
276 275
      *
277
-     * @param  mixed $url String or array of strings that will trigger this route
276
+     * @param  string $url String or array of strings that will trigger this route
278 277
      * @param  array $attr Associative array of route attributes
279 278
      * @param  bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside
280 279
      *
@@ -291,7 +290,7 @@  discard block
 block discarded – undo
291 290
     /**
292 291
      * Adds a POST route, alias of Route::add('POST',$url,$attr,$hideOriginal)
293 292
      *
294
-     * @param  mixed $url String or array of strings that will trigger this route
293
+     * @param  string $url String or array of strings that will trigger this route
295 294
      * @param  array $attr Associative array of route attributes
296 295
      * @param  bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside
297 296
      *
@@ -342,7 +341,7 @@  discard block
 block discarded – undo
342 341
     /**
343 342
      * Adds a DELETE route, alias of Route::add('DELETE',$url,$attr,$hideOriginal)
344 343
      *
345
-     * @param  mixed $url String or array of strings that will trigger this route
344
+     * @param  string $url String or array of strings that will trigger this route
346 345
      * @param  array $attr Associative array of route attributes
347 346
      * @param  bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside
348 347
      *
@@ -380,8 +379,8 @@  discard block
 block discarded – undo
380 379
     /**
381 380
      * Adds a list of routes with the verbs contained in $verbs, alias of Route::add($verbs,$url,$attr,$hideOriginal)
382 381
      *
383
-     * @param  mixed $verb String or array of string of valid HTTP Verbs that will be accepted in this route
384
-     * @param  mixed $url String or array of strings that will trigger this route
382
+     * @param  string[] $verbs String or array of string of valid HTTP Verbs that will be accepted in this route
383
+     * @param  string $url String or array of strings that will trigger this route
385 384
      * @param  array $attr Associative array of route attributes
386 385
      * @param  bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside
387 386
      *
@@ -415,7 +414,6 @@  discard block
 block discarded – undo
415 414
      *
416 415
      * PLEASE NOTE: This is NOT a crud generator, just a bundle of predefined routes.
417 416
      *
418
-     * @param  string $url String or array of strings that will trigger this route
419 417
      * @param  string $controller Controller name (only controller name)
420 418
      * @param  array $attr Associative array of route attributes
421 419
      *
@@ -702,10 +700,6 @@  discard block
 block discarded – undo
702 700
     /**
703 701
      * Creates the 'default_controller' key in CodeIgniter's route array
704 702
      *
705
-     * @param  string $route controller/method name
706
-     * @param  string $alias (Optional) alias of the default controller
707
-     *
708
-     * Due a CodeIgniter limitations, this route MAY NOT be a directory.
709 703
      *
710 704
      * @return void
711 705
      *
@@ -763,7 +757,7 @@  discard block
 block discarded – undo
763 757
     /**
764 758
      * Get all the improved routes defined
765 759
      *
766
-     * @return array List of all defined routes
760
+     * @return Route List of all defined routes
767 761
      *
768 762
      * @access public
769 763
      * @static
@@ -830,7 +824,8 @@  discard block
 block discarded – undo
830 824
      *  This is the 'reverse' process of the improved routing, it'll take the current
831 825
      *  uri string and attempts to find a CodeIgniter route that matches with his pattern
832 826
      *
833
-     * @param  string $search The current uri string
827
+     * @param Middleware $path
828
+     * @param string $requestMethod
834 829
      */
835 830
     public static function getRouteByPath($path, $requestMethod = NULL)
836 831
     {
@@ -879,7 +874,7 @@  discard block
 block discarded – undo
879 874
     /**
880 875
      * Returns an array with the valid HTTP Verbs used in routes
881 876
      *
882
-     * @return array
877
+     * @return Route
883 878
      *
884 879
      * @access public
885 880
      * @static
Please login to merge, or discard this 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.
Braces   +107 added lines, -78 removed lines patch added patch discarded remove patch
@@ -149,11 +149,13 @@  discard block
 block discarded – undo
149 149
         $controller = $parsedController[1];
150 150
         $method     = $parsedController[2];
151 151
 
152
-        if(!is_string($path))
153
-            show_error('Route path must be a string ', 500, 'Route error: bad route path');
152
+        if(!is_string($path)) {
153
+                    show_error('Route path must be a string ', 500, 'Route error: bad route path');
154
+        }
154 155
 
155
-        if(!is_string($verb))
156
-            show_error('Route HTTP Verb must be a string', 500, 'Route error: bad verb type');
156
+        if(!is_string($verb)) {
157
+                    show_error('Route HTTP Verb must be a string', 500, 'Route error: bad verb type');
158
+        }
157 159
 
158 160
         $verb = strtoupper($verb);
159 161
 
@@ -182,38 +184,47 @@  discard block
 block discarded – undo
182 184
         if(isset($attr['as']))
183 185
         {
184 186
             $route['name'] = $attr['as'];
185
-        }
186
-        else
187
+        } else
187 188
         {
188 189
             $route['name'] = NULL;
189 190
         }
190 191
 
191 192
         $route['prefix'] = NULL;
192 193
 
193
-        if(!is_null(self::$prefix))
194
-            $route['prefix'] = self::$prefix;   # Group
195
-        if(isset($attr['prefix']))
196
-            $route['prefix'] = $attr['prefix']; # Specific (will overwrite group prefix)
194
+        if(!is_null(self::$prefix)) {
195
+                    $route['prefix'] = self::$prefix;
196
+        }
197
+        # Group
198
+        if(isset($attr['prefix'])) {
199
+                    $route['prefix'] = $attr['prefix'];
200
+        }
201
+        # Specific (will overwrite group prefix)
197 202
 
198 203
         $route['namespace'] = NULL;
199 204
 
200
-        if(!is_null(self::$namespace))
201
-            $route['namespace'] = self::$namespace;   # Group
202
-        if(isset($attr['namespace']))
203
-            $route['namespace'] = $attr['namespace']; # Specific (will overwrite group namespace)
205
+        if(!is_null(self::$namespace)) {
206
+                    $route['namespace'] = self::$namespace;
207
+        }
208
+        # Group
209
+        if(isset($attr['namespace'])) {
210
+                    $route['namespace'] = $attr['namespace'];
211
+        }
212
+        # Specific (will overwrite group namespace)
204 213
 
205 214
         # Removing trailing slashes
206 215
         if(!is_null($route['prefix']))
207 216
         {
208 217
             $route['prefix'] = trim($route['prefix'],'/');
209
-            if($route['prefix'] == '')
210
-                $route['prefix'] = NULL;
218
+            if($route['prefix'] == '') {
219
+                            $route['prefix'] = NULL;
220
+            }
211 221
         }
212 222
         if(!is_null($route['namespace']))
213 223
         {
214 224
             $route['namespace'] = trim($route['namespace'],'/');
215
-            if($route['namespace'] == '')
216
-                $route['namespace'] = NULL;
225
+            if($route['namespace'] == '') {
226
+                            $route['namespace'] = NULL;
227
+            }
217 228
         }
218 229
 
219 230
         $route['middleware'] = array();
@@ -222,14 +233,14 @@  discard block
 block discarded – undo
222 233
         {
223 234
             if(is_array($attr['middleware']))
224 235
             {
225
-                foreach($attr['middleware'] as $middleware)
226
-                    $route['middleware'][] = $middleware; # Group
227
-            }
228
-            elseif( is_string($attr['middleware']))
236
+                foreach($attr['middleware'] as $middleware) {
237
+                                    $route['middleware'][] = $middleware;
238
+                }
239
+                # Group
240
+            } elseif( is_string($attr['middleware']))
229 241
             {
230 242
                 $route['middleware'][] = $attr['middleware']; # Group
231
-            }
232
-            else
243
+            } else
233 244
             {
234 245
                 show_error('Route middleware must be a string or an array',500,'Route error: bad middleware format');
235 246
             }
@@ -264,8 +275,7 @@  discard block
 block discarded – undo
264 275
         if(!$return)
265 276
         {
266 277
             self::$routes[] = (object) $route;
267
-        }
268
-        else
278
+        } else
269 279
         {
270 280
             return (object) $route;
271 281
         }
@@ -392,8 +402,9 @@  discard block
 block discarded – undo
392 402
      */
393 403
     public static function matches($verbs, $url, $attr, $hideOriginal = FALSE)
394 404
     {
395
-        if(!is_array($verbs))
396
-            show_error('Route::matches() first argument must be an array of valid HTTP Verbs', 500, 'Route error: bad Route::matches() verb list');
405
+        if(!is_array($verbs)) {
406
+                    show_error('Route::matches() first argument must be an array of valid HTTP Verbs', 500, 'Route error: bad Route::matches() verb list');
407
+        }
397 408
 
398 409
         foreach($verbs as $verb)
399 410
         {
@@ -430,17 +441,21 @@  discard block
 block discarded – undo
430 441
 
431 442
         $hideOriginal = FALSE;
432 443
 
433
-        if(isset($attr['namespace']))
434
-            $base_attr['namespace']  = $attr['namespace'];
444
+        if(isset($attr['namespace'])) {
445
+                    $base_attr['namespace']  = $attr['namespace'];
446
+        }
435 447
 
436
-        if(isset($attr['middleware']))
437
-            $base_attr['middleware'] = $attr['middleware'];
448
+        if(isset($attr['middleware'])) {
449
+                    $base_attr['middleware'] = $attr['middleware'];
450
+        }
438 451
 
439
-        if(isset($attr['hideOriginal']))
440
-            $hideOriginal = (bool) $attr['hideOriginal'];
452
+        if(isset($attr['hideOriginal'])) {
453
+                    $hideOriginal = (bool) $attr['hideOriginal'];
454
+        }
441 455
 
442
-        if(isset($attr['prefix']))
443
-            $base_attr['prefix']  = $attr['prefix'];
456
+        if(isset($attr['prefix'])) {
457
+                    $base_attr['prefix']  = $attr['prefix'];
458
+        }
444 459
 
445 460
         $only = array();
446 461
 
@@ -449,8 +464,7 @@  discard block
 block discarded – undo
449 464
             if(is_array($attr['only']))
450 465
             {
451 466
                 $only  = strtolower($attr['only']);
452
-            }
453
-            else
467
+            } else
454 468
             {
455 469
                 $only[] = strtolower($attr['only']);
456 470
             }
@@ -526,16 +540,19 @@  discard block
 block discarded – undo
526 540
 
527 541
         $path = $route->path;
528 542
 
529
-        if(!is_null($prefix))
530
-            $path = $prefix.'/'.$path;
543
+        if(!is_null($prefix)) {
544
+                    $path = $prefix.'/'.$path;
545
+        }
531 546
 
532
-        if(substr($path, 0, 1) == "/" && strlen($path) > 1)
533
-            $path = substr($path,1);
547
+        if(substr($path, 0, 1) == "/" && strlen($path) > 1) {
548
+                    $path = substr($path,1);
549
+        }
534 550
 
535 551
         $controller = $route->controller.'/'.$route->method;
536 552
 
537
-        if(!is_null($namespace))
538
-            $controller = $namespace.'/'.$controller;
553
+        if(!is_null($namespace)) {
554
+                    $controller = $namespace.'/'.$controller;
555
+        }
539 556
 
540 557
         $replaces =
541 558
             [
@@ -601,12 +618,14 @@  discard block
 block discarded – undo
601 618
             $path = key($route);
602 619
             $_404 = $route[$path];
603 620
 
604
-            if(!isset($routes[$path]))
605
-                $routes[$path] = $_404;
621
+            if(!isset($routes[$path])) {
622
+                            $routes[$path] = $_404;
623
+            }
606 624
         }
607 625
 
608
-        if(is_null(self::$defaultController))
609
-            show_error('You must specify a home route: Route::home() as default controller!', 500, 'Route error: missing default controller');
626
+        if(is_null(self::$defaultController)) {
627
+                    show_error('You must specify a home route: Route::home() as default controller!', 500, 'Route error: missing default controller');
628
+        }
610 629
 
611 630
         $defaultController = self::$defaultController->compiled;
612 631
         $defaultController = $defaultController[key($defaultController)];
@@ -632,11 +651,13 @@  discard block
 block discarded – undo
632 651
      */
633 652
     public static function group($attr, $routes)
634 653
     {
635
-        if(!is_array($attr))
636
-            show_error('Group attribute must be a valid array');
654
+        if(!is_array($attr)) {
655
+                    show_error('Group attribute must be a valid array');
656
+        }
637 657
 
638
-        if(!isset($attr['prefix']))
639
-            show_error('You must specify an prefix!');
658
+        if(!isset($attr['prefix'])) {
659
+                    show_error('You must specify an prefix!');
660
+        }
640 661
 
641 662
         self::$prefix = $attr['prefix'];
642 663
 
@@ -648,8 +669,7 @@  discard block
 block discarded – undo
648 669
         if(isset($attr['hideOriginals']) && $attr['hideOriginals'] === TRUE)
649 670
         {
650 671
             self::$hideOriginals = TRUE;
651
-        }
652
-        else
672
+        } else
653 673
         {
654 674
             self::$hideOriginals = FALSE;
655 675
         }
@@ -661,15 +681,14 @@  discard block
 block discarded – undo
661 681
                 //self::$middleware = $attr['middleware'];
662 682
                 if(is_array($attr['middleware']) && !empty($attr['middleware']))
663 683
                 {
664
-                    foreach($attr['middleware'] as $middleware)
665
-                        self::$groupMiddleware[] = [ $attr['prefix'] => $middleware ];
666
-                }
667
-                else
684
+                    foreach($attr['middleware'] as $middleware) {
685
+                                            self::$groupMiddleware[] = [ $attr['prefix'] => $middleware ];
686
+                    }
687
+                } else
668 688
                 {
669 689
                     self::$groupMiddleware[] = [ $attr['prefix'] => $attr['middleware'] ];
670 690
                 }
671
-            }
672
-            else
691
+            } else
673 692
             {
674 693
                 show_error('Group middleware not valid');
675 694
             }
@@ -684,8 +703,10 @@  discard block
 block discarded – undo
684 703
             $controller = $uri[0];
685 704
             $method = isset($uri[1]) ? $uri[1] : NULL;
686 705
 
687
-            if(self::$hideOriginals === TRUE)
688
-                self::$hiddenRoutes[] = [$controller => function(){ show_404(); }];
706
+            if(self::$hideOriginals === TRUE) {
707
+                            self::$hiddenRoutes[] = [$controller => function(){ show_404();
708
+            }
709
+            }];
689 710
 
690 711
             $route_attr['uses'] = $controller.( !is_null($method) ? '/'.$method : '');
691 712
             self::get('/', $route_attr);
@@ -720,14 +741,17 @@  discard block
 block discarded – undo
720 741
                 'as'   => $as
721 742
             ];
722 743
 
723
-        if(!is_null($attr) && !is_array($attr))
724
-            show_error('Default controller attributes must be an array',500,'Route error: bad attribute type');
744
+        if(!is_null($attr) && !is_array($attr)) {
745
+                    show_error('Default controller attributes must be an array',500,'Route error: bad attribute type');
746
+        }
725 747
 
726
-        if(!is_null($attr))
727
-            $routeAttr = array_merge($routeAttr,$attr);
748
+        if(!is_null($attr)) {
749
+                    $routeAttr = array_merge($routeAttr,$attr);
750
+        }
728 751
 
729
-        if(isset($attr['prefix']))
730
-            show_error('Default controller may not have a prefix!',500,'Route error: prefix not allowed');
752
+        if(isset($attr['prefix'])) {
753
+                    show_error('Default controller may not have a prefix!',500,'Route error: prefix not allowed');
754
+        }
731 755
 
732 756
         self::$defaultController = self::$routes[] = self::add('GET', '/', ['uses' => $controller, 'as' => $as],TRUE, TRUE);
733 757
     }
@@ -817,8 +841,9 @@  discard block
 block discarded – undo
817 841
     {
818 842
         foreach(self::$routes as $route)
819 843
         {
820
-            if($route->name == $search)
821
-                return base_url(self::compileRoute($route)->path);
844
+            if($route->name == $search) {
845
+                            return base_url(self::compileRoute($route)->path);
846
+            }
822 847
         }
823 848
 
824 849
         show_error('The route "'.$search.'" is not defined', 500, 'Route error');
@@ -841,14 +866,17 @@  discard block
 block discarded – undo
841 866
             $routes[$route->verb][] = $route;
842 867
         }
843 868
 
844
-        if(empty($routes))
845
-            return FALSE;
869
+        if(empty($routes)) {
870
+                    return FALSE;
871
+        }
846 872
 
847
-        if(is_null($requestMethod))
848
-            $requestMethod = $_SERVER['REQUEST_METHOD'];
873
+        if(is_null($requestMethod)) {
874
+                    $requestMethod = $_SERVER['REQUEST_METHOD'];
875
+        }
849 876
 
850
-        if(!isset($routes[$requestMethod]))
851
-            return FALSE;
877
+        if(!isset($routes[$requestMethod])) {
878
+                    return FALSE;
879
+        }
852 880
 
853 881
         $routes = $routes[$requestMethod];
854 882
 
@@ -868,8 +896,9 @@  discard block
 block discarded – undo
868 896
             {
869 897
                 $compiled = $route->compiled;
870 898
 
871
-                if($findPath == key($compiled))
872
-                    return $route;
899
+                if($findPath == key($compiled)) {
900
+                                    return $route;
901
+                }
873 902
             }
874 903
         }
875 904
 
Please login to merge, or discard this patch.
src/Middleware/Request.php 2 patches
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.
Braces   +13 added lines, -14 removed lines patch added patch discarded remove patch
@@ -65,20 +65,22 @@  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))
69
-            $formMethod = strtoupper($_POST['_method']);
68
+        if(isset($_POST['_method']) && in_array(strtoupper($_POST['_method']), $validMethods , TRUE)) {
69
+                    $formMethod = strtoupper($_POST['_method']);
70
+        }
70 71
 
71 72
         if(is_null($formMethod))
72 73
         {
73 74
             $this->requestMethod = $requestMethod;
74
-        }
75
-        else
75
+        } else
76 76
         {
77
-            if($requestMethod == 'POST')
78
-                $this->requestMethod = $formMethod;
77
+            if($requestMethod == 'POST') {
78
+                            $this->requestMethod = $formMethod;
79
+            }
79 80
 
80
-            if(!$this->CI->input->is_ajax_request() && $this->requestMethod == 'HEAD')
81
-                $this->requestMethod = 'POST';
81
+            if(!$this->CI->input->is_ajax_request() && $this->requestMethod == 'HEAD') {
82
+                            $this->requestMethod = 'POST';
83
+            }
82 84
         }
83 85
     }
84 86
 
@@ -96,8 +98,7 @@  discard block
 block discarded – undo
96 98
             if(ENVIRONMENT != 'production')
97 99
             {
98 100
                 show_error('The request method '.$this->requestMethod.' is not allowed to view the resource', 403, 'Forbidden method');
99
-            }
100
-            else
101
+            } else
101 102
             {
102 103
                 show_404();
103 104
             }
@@ -111,14 +112,12 @@  discard block
 block discarded – undo
111 112
 
112 113
             $this->CI->output->_display();
113 114
             exit(0);
114
-        }
115
-        else
115
+        } else
116 116
         {
117 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
-            }
121
-            else
120
+            } else
122 121
             {
123 122
                 show_404();
124 123
             }
Please login to merge, or discard this patch.
src/Core/Middleware.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -116,7 +116,7 @@
 block discarded – undo
116 116
                 if( $search === $path )
117 117
                 {
118 118
                     if(!in_array($middleware,$_run))
119
-                         $_run[] = $middleware;
119
+                            $_run[] = $middleware;
120 120
                 }
121 121
             }
122 122
         }
Please login to merge, or discard this 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.
Braces   +21 added lines, -14 removed lines patch added patch discarded remove patch
@@ -98,8 +98,9 @@  discard block
 block discarded – undo
98 98
         {
99 99
             foreach($currentRoute->middleware as $middleware)
100 100
             {
101
-                if(!in_array($middleware,$_run))
102
-                    $_run[] = $middleware;
101
+                if(!in_array($middleware,$_run)) {
102
+                                    $_run[] = $middleware;
103
+                }
103 104
             }
104 105
         }
105 106
 
@@ -115,8 +116,9 @@  discard block
 block discarded – undo
115 116
 
116 117
                 if( $search === $path )
117 118
                 {
118
-                    if(!in_array($middleware,$_run))
119
-                         $_run[] = $middleware;
119
+                    if(!in_array($middleware,$_run)) {
120
+                                             $_run[] = $middleware;
121
+                    }
120 122
                 }
121 123
             }
122 124
         }
@@ -145,31 +147,36 @@  discard block
 block discarded – undo
145 147
 
146 148
         $middlewareName = ucfirst($middlewareName).'_middleware';
147 149
 
148
-        if(!file_exists($middlewareDir))
149
-            show_error('Unable to find (or read) the middleware folder: "'.$middlewareDir.'"');
150
+        if(!file_exists($middlewareDir)) {
151
+                    show_error('Unable to find (or read) the middleware folder: "'.$middlewareDir.'"');
152
+        }
150 153
 
151 154
         $runMiddleware =  $middlewareDir.$middlewareName.'.php';
152 155
 
153
-        if(!file_exists($runMiddleware))
154
-            show_error('Unable to find (or read) the middleware "'.$runMiddleware.'"');
156
+        if(!file_exists($runMiddleware)) {
157
+                    show_error('Unable to find (or read) the middleware "'.$runMiddleware.'"');
158
+        }
155 159
 
156 160
         require $runMiddleware;
157 161
 
158
-        if(!class_exists($middlewareName))
159
-            show_error('Class "'.$middlewareName.'" not found');
162
+        if(!class_exists($middlewareName)) {
163
+                    show_error('Class "'.$middlewareName.'" not found');
164
+        }
160 165
 
161 166
         $middleware = new $middlewareName();
162 167
 
163 168
         // Call the current controller __beforeMiddleware() method, if exists:
164
-        if(method_exists(self::$instance, '_beforeMiddleware'))
165
-            self::$instance->_beforeMiddleware();
169
+        if(method_exists(self::$instance, '_beforeMiddleware')) {
170
+                    self::$instance->_beforeMiddleware();
171
+        }
166 172
 
167 173
         // Run the middleware
168 174
         $middleware->run();
169 175
 
170 176
         // Call the current controller _afterMiddleware() method, if exists:
171
-        if(method_exists(self::$instance, '_afterMiddleware'))
172
-            self::$instance->_afterMiddleware();
177
+        if(method_exists(self::$instance, '_afterMiddleware')) {
178
+                    self::$instance->_afterMiddleware();
179
+        }
173 180
 
174 181
     }
175 182
 }
Please login to merge, or discard this patch.