Completed
Push — master ( 9056d3...546896 )
by Anderson
01:59
created
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/Middleware/Request.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -64,19 +64,19 @@  discard block
 block discarded – undo
64 64
 
65 65
         // FIXME: Solve ambiguity here! POST with _method="GET" makes no sense
66 66
 
67
-        if(isset($_POST['_method']) && in_array(strtoupper($_POST['_method']), $validMethods , TRUE))
67
+        if (isset($_POST['_method']) && in_array(strtoupper($_POST['_method']), $validMethods, TRUE))
68 68
             $formMethod = strtoupper($_POST['_method']);
69 69
 
70
-        if(is_null($formMethod))
70
+        if (is_null($formMethod))
71 71
         {
72 72
             $this->requestMethod = $requestMethod;
73 73
         }
74 74
         else
75 75
         {
76
-            if($requestMethod == 'POST')
76
+            if ($requestMethod == 'POST')
77 77
                 $this->requestMethod = $formMethod;
78 78
 
79
-            if(!$this->CI->input->is_ajax_request() && $this->requestMethod == 'HEAD')
79
+            if (!$this->CI->input->is_ajax_request() && $this->requestMethod == 'HEAD')
80 80
                 $this->requestMethod = 'POST';
81 81
         }
82 82
     }
@@ -90,14 +90,14 @@  discard block
 block discarded – undo
90 90
      */
91 91
     public function run()
92 92
     {
93
-        if(!$this->route)
93
+        if (!$this->route)
94 94
         {
95
-            if(is_null(Route::get404()))
95
+            if (is_null(Route::get404()))
96 96
                 show_404();
97 97
 
98
-            if(Route::get404()->controller != get_class($this->CI))
98
+            if (Route::get404()->controller != get_class($this->CI))
99 99
             {
100
-                if(ENVIRONMENT != 'production')
100
+                if (ENVIRONMENT != 'production')
101 101
                 {
102 102
                     show_error('The request method '.$this->requestMethod.' is not allowed to view the resource', 403, 'Forbidden method');
103 103
                 }
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
         }
110 110
         else
111 111
         {
112
-            if(method_exists($this->CI,$this->route->method))
112
+            if (method_exists($this->CI, $this->route->method))
113 113
             {
114 114
                 $this->CI->{$this->route->method}();
115 115
 
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
             }
121 121
             else
122 122
             {
123
-                if(ENVIRONMENT != 'production')
123
+                if (ENVIRONMENT != 'production')
124 124
                 {
125 125
                     show_error('The method '.$this->route->controller.'::'.$this->route->method.'() does not exists', 500, 'Method not found');
126 126
                 }
Please login to merge, or discard this patch.
src/Core/Route.php 1 patch
Spacing   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -130,17 +130,17 @@  discard block
 block discarded – undo
130 130
      */
131 131
     public static function add($verb, $path, $attr, $hideOriginal = TRUE, $return = FALSE)
132 132
     {
133
-        if(!is_array($attr))
133
+        if (!is_array($attr))
134 134
         {
135
-            show_error('You must specify the route attributes as an array',500,'Route error: bad attributes');
135
+            show_error('You must specify the route attributes as an array', 500, 'Route error: bad attributes');
136 136
         }
137 137
 
138
-        if(!isset($attr['uses']))
138
+        if (!isset($attr['uses']))
139 139
         {
140 140
             show_error('Route requires a \'controller@method\' to be pointed and it\'s not defined in the route attributes', 500, 'Route error: missing controller');
141 141
         }
142 142
 
143
-        if(!preg_match('/^([a-zA-Z1-9-_]+)@([a-zA-Z1-9-_]+)$/', $attr['uses'], $parsedController) !== FALSE)
143
+        if (!preg_match('/^([a-zA-Z1-9-_]+)@([a-zA-Z1-9-_]+)$/', $attr['uses'], $parsedController) !== FALSE)
144 144
         {
145 145
             show_error('Route controller must be in format controller@method', 500, 'Route error: bad controller format');
146 146
         }
@@ -148,28 +148,28 @@  discard block
 block discarded – undo
148 148
         $controller = $parsedController[1];
149 149
         $method     = $parsedController[2];
150 150
 
151
-        if(!is_string($path))
151
+        if (!is_string($path))
152 152
             show_error('Route path must be a string ', 500, 'Route error: bad route path');
153 153
 
154
-        if(!is_string($verb))
154
+        if (!is_string($verb))
155 155
             show_error('Route HTTP Verb must be a string', 500, 'Route error: bad verb type');
156 156
 
157 157
         $verb = strtoupper($verb);
158 158
 
159
-        if(!in_array($verb, self::$http_verbs,TRUE))
159
+        if (!in_array($verb, self::$http_verbs, TRUE))
160 160
         {
161 161
             $errorMsg = 'Verb "'.$verb.'" is not a valid HTTP Verb, allowed verbs:<ul>';
162
-            foreach( self::$http_verbs as $validVerb )
162
+            foreach (self::$http_verbs as $validVerb)
163 163
             {
164 164
                 $errorMsg .= '<li>'.$validVerb.'</li>';
165 165
             }
166 166
             $errorMsg .= '</ul>';
167
-            show_error($errorMsg,500,'Route error: unknow method');
167
+            show_error($errorMsg, 500, 'Route error: unknow method');
168 168
         }
169 169
 
170 170
         $route['verb'] = $verb;
171 171
 
172
-        $path = trim($path,'/');
172
+        $path = trim($path, '/');
173 173
 
174 174
         //if($path == '')
175 175
         //    $path = '/';
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
         $route['controller'] = $controller;
179 179
         $route['method']     = $method;
180 180
 
181
-        if(isset($attr['as']))
181
+        if (isset($attr['as']))
182 182
         {
183 183
             $route['name'] = $attr['as'];
184 184
         }
@@ -189,48 +189,48 @@  discard block
 block discarded – undo
189 189
 
190 190
         $route['prefix'] = NULL;
191 191
 
192
-        if(!is_null(self::$prefix))
193
-            $route['prefix'] = self::$prefix;   # Group
194
-        if(isset($attr['prefix']))
192
+        if (!is_null(self::$prefix))
193
+            $route['prefix'] = self::$prefix; # Group
194
+        if (isset($attr['prefix']))
195 195
             $route['prefix'] = $attr['prefix']; # Specific (will overwrite group prefix)
196 196
 
197 197
         $route['namespace'] = NULL;
198 198
 
199
-        if(!is_null(self::$namespace))
200
-            $route['namespace'] = self::$namespace;   # Group
201
-        if(isset($attr['namespace']))
199
+        if (!is_null(self::$namespace))
200
+            $route['namespace'] = self::$namespace; # Group
201
+        if (isset($attr['namespace']))
202 202
             $route['namespace'] = $attr['namespace']; # Specific (will overwrite group namespace)
203 203
 
204 204
         # Removing trailing slashes
205
-        if(!is_null($route['prefix']))
205
+        if (!is_null($route['prefix']))
206 206
         {
207
-            $route['prefix'] = trim($route['prefix'],'/');
208
-            if($route['prefix'] == '')
207
+            $route['prefix'] = trim($route['prefix'], '/');
208
+            if ($route['prefix'] == '')
209 209
                 $route['prefix'] = NULL;
210 210
         }
211
-        if(!is_null($route['namespace']))
211
+        if (!is_null($route['namespace']))
212 212
         {
213
-            $route['namespace'] = trim($route['namespace'],'/');
214
-            if($route['namespace'] == '')
213
+            $route['namespace'] = trim($route['namespace'], '/');
214
+            if ($route['namespace'] == '')
215 215
                 $route['namespace'] = NULL;
216 216
         }
217 217
 
218 218
         $route['middleware'] = array();
219 219
 
220
-        if(isset($attr['middleware']))
220
+        if (isset($attr['middleware']))
221 221
         {
222
-            if(is_array($attr['middleware']))
222
+            if (is_array($attr['middleware']))
223 223
             {
224
-                foreach($attr['middleware'] as $middleware)
224
+                foreach ($attr['middleware'] as $middleware)
225 225
                     $route['middleware'][] = $middleware; # Group
226 226
             }
227
-            elseif( is_string($attr['middleware']))
227
+            elseif (is_string($attr['middleware']))
228 228
             {
229 229
                 $route['middleware'][] = $attr['middleware']; # Group
230 230
             }
231 231
             else
232 232
             {
233
-                show_error('Route middleware must be a string or an array',500,'Route error: bad middleware format');
233
+                show_error('Route middleware must be a string or an array', 500, 'Route error: bad middleware format');
234 234
             }
235 235
         }
236 236
 
@@ -240,27 +240,27 @@  discard block
 block discarded – undo
240 240
             $compiledRoute->path => $compiledRoute->route
241 241
         ];
242 242
 
243
-        if($hideOriginal || self::$hideOriginals === TRUE || ($compiledRoute->path != '' && $compiledRoute->path != '/' ) )
243
+        if ($hideOriginal || self::$hideOriginals === TRUE || ($compiledRoute->path != '' && $compiledRoute->path != '/'))
244 244
         {
245 245
             $hiddenRoutePath      = $controller.'/'.$method;
246 246
             $hiddenRouteNamespace = '';
247 247
 
248
-            if(!is_null($route['namespace']))
248
+            if (!is_null($route['namespace']))
249 249
             {
250 250
                 $hiddenRouteNamespace = $route['namespace'].'/';
251 251
             }
252 252
 
253 253
             $hiddenRoutePath = $hiddenRouteNamespace.$hiddenRoutePath;
254 254
 
255
-            if($method == 'index')
255
+            if ($method == 'index')
256 256
             {
257
-                self::$hiddenRoutes[] = [ $hiddenRouteNamespace.$controller  => function(){ show_404(); }];
257
+                self::$hiddenRoutes[] = [$hiddenRouteNamespace.$controller  => function() { show_404(); }];
258 258
             }
259 259
 
260
-            self::$hiddenRoutes[] = [$hiddenRoutePath => function(){ show_404(); }];
260
+            self::$hiddenRoutes[] = [$hiddenRoutePath => function() { show_404(); }];
261 261
         }
262 262
 
263
-        if(!$return)
263
+        if (!$return)
264 264
         {
265 265
             self::$routes[] = (object) $route;
266 266
         }
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
      */
285 285
     public static function get($url, $attr, $hideOriginal = TRUE)
286 286
     {
287
-        self::add('GET', $url,$attr, $hideOriginal);
287
+        self::add('GET', $url, $attr, $hideOriginal);
288 288
     }
289 289
 
290 290
     /**
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
      */
302 302
     public static function post($url, $attr, $hideOriginal = TRUE)
303 303
     {
304
-        self::add('POST', $url,$attr, $hideOriginal);
304
+        self::add('POST', $url, $attr, $hideOriginal);
305 305
     }
306 306
 
307 307
     /**
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
      */
319 319
     public static function put($url, $attr, $hideOriginal = TRUE)
320 320
     {
321
-        self::add('PUT', $url,$attr, $hideOriginal);
321
+        self::add('PUT', $url, $attr, $hideOriginal);
322 322
     }
323 323
 
324 324
     /**
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
      */
336 336
     public static function patch($url, $attr, $hideOriginal = TRUE)
337 337
     {
338
-        self::add('PATCH', $url,$attr, $hideOriginal);
338
+        self::add('PATCH', $url, $attr, $hideOriginal);
339 339
     }
340 340
 
341 341
     /**
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
      */
353 353
     public static function delete($url, $attr, $hideOriginal = TRUE)
354 354
     {
355
-        self::add('DELETE', $url,$attr, $hideOriginal);
355
+        self::add('DELETE', $url, $attr, $hideOriginal);
356 356
     }
357 357
 
358 358
     /**
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
      */
370 370
     public static function any($url, $attr, $hideOriginal = TRUE)
371 371
     {
372
-        foreach(self::$http_verbs as $verb)
372
+        foreach (self::$http_verbs as $verb)
373 373
         {
374 374
             $verb = strtolower($verb);
375 375
             self::add($verb, $url, $attr, $hideOriginal);
@@ -391,10 +391,10 @@  discard block
 block discarded – undo
391 391
      */
392 392
     public static function matches($verbs, $url, $attr, $hideOriginal = FALSE)
393 393
     {
394
-        if(!is_array($verbs))
394
+        if (!is_array($verbs))
395 395
             show_error('Route::matches() first argument must be an array of valid HTTP Verbs', 500, 'Route error: bad Route::matches() verb list');
396 396
 
397
-        foreach($verbs as $verb)
397
+        foreach ($verbs as $verb)
398 398
         {
399 399
             self::add($verb, $url, $attr, $hideOriginal);
400 400
         }
@@ -429,25 +429,25 @@  discard block
 block discarded – undo
429 429
 
430 430
         $hideOriginal = FALSE;
431 431
 
432
-        if(isset($attr['namespace']))
432
+        if (isset($attr['namespace']))
433 433
             $base_attr['namespace']  = $attr['namespace'];
434 434
 
435
-        if(isset($attr['middleware']))
435
+        if (isset($attr['middleware']))
436 436
             $base_attr['middleware'] = $attr['middleware'];
437 437
 
438
-        if(isset($attr['hideOriginal']))
438
+        if (isset($attr['hideOriginal']))
439 439
             $hideOriginal = (bool) $attr['hideOriginal'];
440 440
 
441
-        if(isset($attr['prefix']))
442
-            $base_attr['prefix']  = $attr['prefix'];
441
+        if (isset($attr['prefix']))
442
+            $base_attr['prefix'] = $attr['prefix'];
443 443
 
444 444
         $only = array();
445 445
 
446
-        if(isset($attr['only']) && (is_array($attr['only']) || is_string($attr['only'])))
446
+        if (isset($attr['only']) && (is_array($attr['only']) || is_string($attr['only'])))
447 447
         {
448
-            if(is_array($attr['only']))
448
+            if (is_array($attr['only']))
449 449
             {
450
-                $only  = strtolower($attr['only']);
450
+                $only = strtolower($attr['only']);
451 451
             }
452 452
             else
453 453
             {
@@ -455,43 +455,43 @@  discard block
 block discarded – undo
455 455
             }
456 456
         }
457 457
 
458
-        if(empty($only) || in_array('index', $only))
458
+        if (empty($only) || in_array('index', $only))
459 459
         {
460
-            $route_attr = array_merge($base_attr, ['uses' => $controller.'@index',   'as' => $name.'.index']);
460
+            $route_attr = array_merge($base_attr, ['uses' => $controller.'@index', 'as' => $name.'.index']);
461 461
             self::get('/', $route_attr, $hideOriginal);
462 462
         }
463 463
 
464
-        if(empty($only) || in_array('create', $only))
464
+        if (empty($only) || in_array('create', $only))
465 465
         {
466 466
             $route_attr = array_merge($base_attr, ['uses' => $controller.'@create', 'as' => $name.'.create']);
467 467
             self::get('create', $route_attr, $hideOriginal);
468 468
         }
469 469
 
470
-        if(empty($only) || in_array('store', $only))
470
+        if (empty($only) || in_array('store', $only))
471 471
         {
472 472
             $route_attr = array_merge($base_attr, ['uses' => $controller.'@store', 'as' => $name.'.store']);
473 473
             self::post('/', $route_attr, $hideOriginal);
474 474
         }
475 475
 
476
-        if(empty($only) || in_array('show', $only))
476
+        if (empty($only) || in_array('show', $only))
477 477
         {
478 478
             $route_attr = array_merge($base_attr, ['uses' => $controller.'@show', 'as' => $name.'.show']);
479 479
             self::get('{slug}', $route_attr, $hideOriginal);
480 480
         }
481 481
 
482
-        if(empty($only) || in_array('edit', $only))
482
+        if (empty($only) || in_array('edit', $only))
483 483
         {
484 484
             $route_attr = array_merge($base_attr, ['uses' => $controller.'@edit', 'as' => $name.'.edit']);
485 485
             self::get('{slug}/edit', $route_attr, $hideOriginal);
486 486
         }
487 487
 
488
-        if(empty($only) || in_array('update', $only))
488
+        if (empty($only) || in_array('update', $only))
489 489
         {
490 490
             $route_attr = array_merge($base_attr, ['uses' => $controller.'@update', 'as' => $name.'.update']);
491 491
             self::matches(['PUT', 'PATCH'], '{slug}/update', $route_attr, $hideOriginal);
492 492
         }
493 493
 
494
-        if(empty($only) || in_array('destroy', $only))
494
+        if (empty($only) || in_array('destroy', $only))
495 495
         {
496 496
             $route_attr = array_merge($base_attr, ['uses' => $controller.'@destroy', 'as' => $name.'.destroy']);
497 497
             self::delete('{slug}', $route_attr, $hideOriginal);
@@ -513,32 +513,32 @@  discard block
 block discarded – undo
513 513
         $prefix    = NULL;
514 514
         $namespace = NULL;
515 515
 
516
-        if(!is_null($route->prefix))
516
+        if (!is_null($route->prefix))
517 517
         {
518 518
             $prefix = $route->prefix;
519 519
         }
520 520
 
521
-        if(!is_null($route->namespace))
521
+        if (!is_null($route->namespace))
522 522
         {
523 523
             $namespace = $route->namespace;
524 524
         }
525 525
 
526 526
         $path = $route->path;
527 527
 
528
-        if(!is_null($prefix))
528
+        if (!is_null($prefix))
529 529
             $path = $prefix.'/'.$path;
530 530
 
531
-        if(substr($path, 0, 1) == "/" && strlen($path) > 1)
532
-            $path = substr($path,1);
531
+        if (substr($path, 0, 1) == "/" && strlen($path) > 1)
532
+            $path = substr($path, 1);
533 533
 
534 534
         $controller = $route->controller.'/'.$route->method;
535 535
 
536
-        if(!is_null($namespace))
536
+        if (!is_null($namespace))
537 537
             $controller = $namespace.'/'.$controller;
538 538
 
539 539
         $replaces =
540 540
             [
541
-                '{\((.*)\):[a-zA-Z0-9-_]*}' => '($1)',   # Custom regular expression
541
+                '{\((.*)\):[a-zA-Z0-9-_]*}' => '($1)', # Custom regular expression
542 542
                 '{num:[a-zA-Z0-9-_]*}'      => '(:num)', # (:num) route
543 543
                 '{any:[a-zA-Z0-9-_]*}'      => '(:any)', # (:any) route
544 544
                 '{[a-zA-Z0-9-_]*}'          => '(:any)', # Everything else
@@ -546,23 +546,23 @@  discard block
 block discarded – undo
546 546
 
547 547
         $argCount = 0;
548 548
 
549
-        foreach($replaces as $regex => $replace)
549
+        foreach ($replaces as $regex => $replace)
550 550
         {
551 551
             $path = preg_replace('/'.$regex.'/', $replace, $path, -1, $argCount);
552 552
         }
553 553
 
554
-        if($argCount > 0)
554
+        if ($argCount > 0)
555 555
         {
556
-            for($i = 0; $i < $argCount; $i++)
556
+            for ($i = 0; $i < $argCount; $i++)
557 557
             {
558 558
                 $controller .= '/$'.($i + 1);
559 559
             }
560 560
         }
561 561
 
562 562
         // Removing trailing slash (it causes 404 even if the route exists, I don't know why)
563
-        if(substr($path,-1) == '/')
563
+        if (substr($path, -1) == '/')
564 564
         {
565
-            $path = substr($path,0,-1);
565
+            $path = substr($path, 0, -1);
566 566
         }
567 567
 
568 568
         return (object) [
@@ -583,11 +583,11 @@  discard block
 block discarded – undo
583 583
     {
584 584
         $routes = array();
585 585
 
586
-        foreach(self::$routes as $index => $route)
586
+        foreach (self::$routes as $index => $route)
587 587
         {
588 588
             $compiled = self::compileRoute($route);
589 589
 
590
-            if( !isset($routes[$compiled->path]) || $route->verb == 'GET' )
590
+            if (!isset($routes[$compiled->path]) || $route->verb == 'GET')
591 591
             {
592 592
                 $routes[$compiled->path] = $compiled->route;
593 593
             }
@@ -595,16 +595,16 @@  discard block
 block discarded – undo
595 595
             self::$routes[$index] = (object) $route;
596 596
         }
597 597
 
598
-        foreach(self::$hiddenRoutes as $route)
598
+        foreach (self::$hiddenRoutes as $route)
599 599
         {
600 600
             $path = key($route);
601 601
             $_404 = $route[$path];
602 602
 
603
-            if(!isset($routes[$path]))
603
+            if (!isset($routes[$path]))
604 604
                 $routes[$path] = $_404;
605 605
         }
606 606
 
607
-        if(is_null(self::$defaultController))
607
+        if (is_null(self::$defaultController))
608 608
             show_error('You must specify a home route: Route::home() as default controller!', 500, 'Route error: missing default controller');
609 609
 
610 610
         $defaultController = self::$defaultController->compiled;
@@ -612,7 +612,7 @@  discard block
 block discarded – undo
612 612
 
613 613
         $routes['default_controller'] = $defaultController;
614 614
 
615
-        if(is_null(self::$_404page))
615
+        if (is_null(self::$_404page))
616 616
         {
617 617
             $routes['404_override'] = '';
618 618
         }
@@ -639,20 +639,20 @@  discard block
 block discarded – undo
639 639
      */
640 640
     public static function group($attr, $routes)
641 641
     {
642
-        if(!is_array($attr))
642
+        if (!is_array($attr))
643 643
             show_error('Group attribute must be a valid array');
644 644
 
645
-        if(!isset($attr['prefix']))
645
+        if (!isset($attr['prefix']))
646 646
             show_error('You must specify an prefix!');
647 647
 
648 648
         self::$prefix = $attr['prefix'];
649 649
 
650
-        if(isset($attr['namespace']))
650
+        if (isset($attr['namespace']))
651 651
         {
652 652
             self::$namespace = $attr['namespace'];
653 653
         }
654 654
 
655
-        if(isset($attr['hideOriginals']) && $attr['hideOriginals'] === TRUE)
655
+        if (isset($attr['hideOriginals']) && $attr['hideOriginals'] === TRUE)
656 656
         {
657 657
             self::$hideOriginals = TRUE;
658 658
         }
@@ -661,19 +661,19 @@  discard block
 block discarded – undo
661 661
             self::$hideOriginals = FALSE;
662 662
         }
663 663
 
664
-        if(isset($attr['middleware']))
664
+        if (isset($attr['middleware']))
665 665
         {
666
-            if(is_array($attr['middleware']) || is_string($attr['middleware']))
666
+            if (is_array($attr['middleware']) || is_string($attr['middleware']))
667 667
             {
668 668
                 //self::$middleware = $attr['middleware'];
669
-                if(is_array($attr['middleware']) && !empty($attr['middleware']))
669
+                if (is_array($attr['middleware']) && !empty($attr['middleware']))
670 670
                 {
671
-                    foreach($attr['middleware'] as $middleware)
672
-                        self::$groupMiddleware[] = [ $attr['prefix'] => $middleware ];
671
+                    foreach ($attr['middleware'] as $middleware)
672
+                        self::$groupMiddleware[] = [$attr['prefix'] => $middleware];
673 673
                 }
674 674
                 else
675 675
                 {
676
-                    self::$groupMiddleware[] = [ $attr['prefix'] => $attr['middleware'] ];
676
+                    self::$groupMiddleware[] = [$attr['prefix'] => $attr['middleware']];
677 677
                 }
678 678
             }
679 679
             else
@@ -684,17 +684,17 @@  discard block
 block discarded – undo
684 684
 
685 685
         # Special workarround for default group controller:
686 686
         # Probably i'll remove it.
687
-        if(isset($attr['default']))
687
+        if (isset($attr['default']))
688 688
         {
689 689
             $url = str_ireplace('@', '/', $attr['default']);
690
-            $uri = explode('/',$attr['default']);
690
+            $uri = explode('/', $attr['default']);
691 691
             $controller = $uri[0];
692 692
             $method = isset($uri[1]) ? $uri[1] : NULL;
693 693
 
694
-            if(self::$hideOriginals === TRUE)
695
-                self::$hiddenRoutes[] = [$controller => function(){ show_404(); }];
694
+            if (self::$hideOriginals === TRUE)
695
+                self::$hiddenRoutes[] = [$controller => function() { show_404(); }];
696 696
 
697
-            $route_attr['uses'] = $controller.( !is_null($method) ? '/'.$method : '');
697
+            $route_attr['uses'] = $controller.(!is_null($method) ? '/'.$method : '');
698 698
             self::get('/', $route_attr);
699 699
         }
700 700
 
@@ -727,16 +727,16 @@  discard block
 block discarded – undo
727 727
                 'as'   => $as
728 728
             ];
729 729
 
730
-        if(!is_null($attr) && !is_array($attr))
731
-            show_error('Default controller attributes must be an array',500,'Route error: bad attribute type');
730
+        if (!is_null($attr) && !is_array($attr))
731
+            show_error('Default controller attributes must be an array', 500, 'Route error: bad attribute type');
732 732
 
733
-        if(!is_null($attr))
734
-            $routeAttr = array_merge($routeAttr,$attr);
733
+        if (!is_null($attr))
734
+            $routeAttr = array_merge($routeAttr, $attr);
735 735
 
736
-        if(isset($attr['prefix']))
737
-            show_error('Default controller may not have a prefix!',500,'Route error: prefix not allowed');
736
+        if (isset($attr['prefix']))
737
+            show_error('Default controller may not have a prefix!', 500, 'Route error: prefix not allowed');
738 738
 
739
-        self::$defaultController = self::$routes[] = self::add('GET', '/', ['uses' => $controller, 'as' => $as],TRUE, TRUE);
739
+        self::$defaultController = self::$routes[] = self::add('GET', '/', ['uses' => $controller, 'as' => $as], TRUE, TRUE);
740 740
     }
741 741
 
742 742
     /**
@@ -754,14 +754,14 @@  discard block
 block discarded – undo
754 754
         $baseAttr['prefix']     = 'auth';
755 755
         $baseAttr['middleware'] = 'Auth';
756 756
 
757
-        if(!is_null($attr) && is_array($attr))
757
+        if (!is_null($attr) && is_array($attr))
758 758
         {
759 759
             $baseAttr = array_merge($baseAttr, $attr);
760 760
         }
761 761
 
762 762
         self::group($baseAttr, function() use($controller)
763 763
         {
764
-            self::matches(['get','post'], '/login',  ['uses' => $controller.'@login',  'as' => $controller.'.login']);
764
+            self::matches(['get', 'post'], '/login', ['uses' => $controller.'@login', 'as' => $controller.'.login']);
765 765
             self::get('/logout', ['uses' => $controller.'@logout', 'as' => $controller.'.logout']);
766 766
         });
767 767
     }
@@ -822,9 +822,9 @@  discard block
 block discarded – undo
822 822
      */
823 823
     public static function getRouteByName($search, $args = NULL)
824 824
     {
825
-        foreach(self::$routes as $route)
825
+        foreach (self::$routes as $route)
826 826
         {
827
-            if($route->name == $search)
827
+            if ($route->name == $search)
828 828
                 return base_url(self::compileRoute($route)->path);
829 829
         }
830 830
 
@@ -845,18 +845,18 @@  discard block
 block discarded – undo
845 845
     {
846 846
         $routes = array();
847 847
 
848
-        foreach(self::$routes as $route)
848
+        foreach (self::$routes as $route)
849 849
         {
850 850
             $routes[$route->verb][] = $route;
851 851
         }
852 852
 
853
-        if(empty($routes))
853
+        if (empty($routes))
854 854
             return FALSE;
855 855
 
856
-        if(is_null($requestMethod))
856
+        if (is_null($requestMethod))
857 857
             $requestMethod = $_SERVER['REQUEST_METHOD'];
858 858
 
859
-        if(!isset($routes[$requestMethod]))
859
+        if (!isset($routes[$requestMethod]))
860 860
             return FALSE;
861 861
 
862 862
         $routes = $routes[$requestMethod];
@@ -866,18 +866,18 @@  discard block
 block discarded – undo
866 866
 
867 867
         $path = trim($path);
868 868
 
869
-        if($path == '')
869
+        if ($path == '')
870 870
         {
871 871
             return self::$defaultController;
872 872
         }
873 873
 
874
-        foreach( [$path, $path.'/index'] as $findPath )
874
+        foreach ([$path, $path.'/index'] as $findPath)
875 875
         {
876
-            foreach($routes as $route)
876
+            foreach ($routes as $route)
877 877
             {
878 878
                 $compiled = $route->compiled;
879 879
 
880
-                if($findPath == key($compiled))
880
+                if ($findPath == key($compiled))
881 881
                     return $route;
882 882
             }
883 883
         }
Please login to merge, or discard this patch.