Completed
Push — master ( 9056d3...546896 )
by Anderson
01:59
created
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.
src/Core/Route.php 3 patches
Doc Comments   +13 added lines, -19 removed lines patch added patch discarded remove patch
@@ -119,7 +119,6 @@  discard block
 block discarded – undo
119 119
      * Generic method to add a improved route
120 120
      *
121 121
      * @param  mixed $verb String or array of string of valid HTTP Verbs that will be accepted in this route
122
-     * @param  mixed $url String or array of strings that will trigger this route
123 122
      * @param  array $attr Associative array of route attributes
124 123
      * @param  bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside
125 124
      *
@@ -273,7 +272,7 @@  discard block
 block discarded – undo
273 272
     /**
274 273
      * Adds a GET route, alias of Route::add('GET',$url,$attr,$hideOriginal)
275 274
      *
276
-     * @param  mixed $url String or array of strings that will trigger this route
275
+     * @param  string $url String or array of strings that will trigger this route
277 276
      * @param  array $attr Associative array of route attributes
278 277
      * @param  bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside
279 278
      *
@@ -290,7 +289,7 @@  discard block
 block discarded – undo
290 289
     /**
291 290
      * Adds a POST route, alias of Route::add('POST',$url,$attr,$hideOriginal)
292 291
      *
293
-     * @param  mixed $url String or array of strings that will trigger this route
292
+     * @param  string $url String or array of strings that will trigger this route
294 293
      * @param  array $attr Associative array of route attributes
295 294
      * @param  bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside
296 295
      *
@@ -341,7 +340,7 @@  discard block
 block discarded – undo
341 340
     /**
342 341
      * Adds a DELETE route, alias of Route::add('DELETE',$url,$attr,$hideOriginal)
343 342
      *
344
-     * @param  mixed $url String or array of strings that will trigger this route
343
+     * @param  string $url String or array of strings that will trigger this route
345 344
      * @param  array $attr Associative array of route attributes
346 345
      * @param  bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside
347 346
      *
@@ -379,8 +378,8 @@  discard block
 block discarded – undo
379 378
     /**
380 379
      * Adds a list of routes with the verbs contained in $verbs, alias of Route::add($verbs,$url,$attr,$hideOriginal)
381 380
      *
382
-     * @param  mixed $verb String or array of string of valid HTTP Verbs that will be accepted in this route
383
-     * @param  mixed $url String or array of strings that will trigger this route
381
+     * @param  string[] $verbs String or array of string of valid HTTP Verbs that will be accepted in this route
382
+     * @param  string $url String or array of strings that will trigger this route
384 383
      * @param  array $attr Associative array of route attributes
385 384
      * @param  bool $hideOriginal (Optional) map the original $url as a route with a show_404() callback inside
386 385
      *
@@ -414,7 +413,6 @@  discard block
 block discarded – undo
414 413
      *
415 414
      * PLEASE NOTE: This is NOT a crud generator, just a bundle of predefined routes.
416 415
      *
417
-     * @param  string $url String or array of strings that will trigger this route
418 416
      * @param  string $controller Controller name (only controller name)
419 417
      * @param  array $attr Associative array of route attributes
420 418
      *
@@ -709,10 +707,6 @@  discard block
 block discarded – undo
709 707
     /**
710 708
      * Creates the 'default_controller' key in CodeIgniter's route array
711 709
      *
712
-     * @param  string $route controller/method name
713
-     * @param  string $alias (Optional) alias of the default controller
714
-     *
715
-     * Due a CodeIgniter limitations, this route MAY NOT be a directory.
716 710
      *
717 711
      * @return void
718 712
      *
@@ -770,7 +764,7 @@  discard block
 block discarded – undo
770 764
     /**
771 765
      * Get all the improved routes defined
772 766
      *
773
-     * @return array List of all defined routes
767
+     * @return Route List of all defined routes
774 768
      *
775 769
      * @access public
776 770
      * @static
@@ -783,7 +777,7 @@  discard block
 block discarded – undo
783 777
     /**
784 778
      * Get all hidden routes
785 779
      *
786
-     * @return array
780
+     * @return Route
787 781
      *
788 782
      * @access public
789 783
      * @static
@@ -799,7 +793,7 @@  discard block
 block discarded – undo
799 793
      * This middleware actually works as uri filter since they will not check the route,
800 794
      * just check if the current uri string matches the prefix of the route group.
801 795
      *
802
-     * @return array
796
+     * @return Route
803 797
      *
804 798
      * @access public
805 799
      * @static
@@ -837,8 +831,9 @@  discard block
 block discarded – undo
837 831
      *  This is the 'reverse' process of the improved routing, it'll take the current
838 832
      *  uri string and attempts to find a CodeIgniter route that matches with his pattern
839 833
      *
840
-     * @param  string $search The current uri string
841 834
      *
835
+     * @param Middleware $path
836
+     * @param string $requestMethod
842 837
      * @return mixed
843 838
      */
844 839
     public static function getRouteByPath($path, $requestMethod = NULL)
@@ -888,7 +883,7 @@  discard block
 block discarded – undo
888 883
     /**
889 884
      * Returns an array with the valid HTTP Verbs used in routes
890 885
      *
891
-     * @return array
886
+     * @return Route
892 887
      *
893 888
      * @access public
894 889
      * @static
@@ -903,7 +898,6 @@  discard block
 block discarded – undo
903 898
      * Set the 404 error controller ($route['404_override'])
904 899
      *
905 900
      * @param  string  $controller
906
-     * @param  string  $namespace (Optional)
907 901
      *
908 902
      * @return void
909 903
      *
@@ -922,9 +916,9 @@  discard block
 block discarded – undo
922 916
     /**
923 917
      * Get the 404 route
924 918
      *
925
-     * @return array $_404page
919
+     * @return Route $_404page
926 920
      *
927
-     * @return object | null
921
+     * @return Route | null
928 922
      *
929 923
      * @access public
930 924
      * @static
Please login to merge, or discard this 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.
Braces   +108 added lines, -80 removed lines patch added patch discarded remove patch
@@ -148,11 +148,13 @@  discard block
 block discarded – undo
148 148
         $controller = $parsedController[1];
149 149
         $method     = $parsedController[2];
150 150
 
151
-        if(!is_string($path))
152
-            show_error('Route path must be a string ', 500, 'Route error: bad route path');
151
+        if(!is_string($path)) {
152
+                    show_error('Route path must be a string ', 500, 'Route error: bad route path');
153
+        }
153 154
 
154
-        if(!is_string($verb))
155
-            show_error('Route HTTP Verb must be a string', 500, 'Route error: bad verb type');
155
+        if(!is_string($verb)) {
156
+                    show_error('Route HTTP Verb must be a string', 500, 'Route error: bad verb type');
157
+        }
156 158
 
157 159
         $verb = strtoupper($verb);
158 160
 
@@ -181,38 +183,47 @@  discard block
 block discarded – undo
181 183
         if(isset($attr['as']))
182 184
         {
183 185
             $route['name'] = $attr['as'];
184
-        }
185
-        else
186
+        } else
186 187
         {
187 188
             $route['name'] = NULL;
188 189
         }
189 190
 
190 191
         $route['prefix'] = NULL;
191 192
 
192
-        if(!is_null(self::$prefix))
193
-            $route['prefix'] = self::$prefix;   # Group
194
-        if(isset($attr['prefix']))
195
-            $route['prefix'] = $attr['prefix']; # Specific (will overwrite group prefix)
193
+        if(!is_null(self::$prefix)) {
194
+                    $route['prefix'] = self::$prefix;
195
+        }
196
+        # Group
197
+        if(isset($attr['prefix'])) {
198
+                    $route['prefix'] = $attr['prefix'];
199
+        }
200
+        # Specific (will overwrite group prefix)
196 201
 
197 202
         $route['namespace'] = NULL;
198 203
 
199
-        if(!is_null(self::$namespace))
200
-            $route['namespace'] = self::$namespace;   # Group
201
-        if(isset($attr['namespace']))
202
-            $route['namespace'] = $attr['namespace']; # Specific (will overwrite group namespace)
204
+        if(!is_null(self::$namespace)) {
205
+                    $route['namespace'] = self::$namespace;
206
+        }
207
+        # Group
208
+        if(isset($attr['namespace'])) {
209
+                    $route['namespace'] = $attr['namespace'];
210
+        }
211
+        # Specific (will overwrite group namespace)
203 212
 
204 213
         # Removing trailing slashes
205 214
         if(!is_null($route['prefix']))
206 215
         {
207 216
             $route['prefix'] = trim($route['prefix'],'/');
208
-            if($route['prefix'] == '')
209
-                $route['prefix'] = NULL;
217
+            if($route['prefix'] == '') {
218
+                            $route['prefix'] = NULL;
219
+            }
210 220
         }
211 221
         if(!is_null($route['namespace']))
212 222
         {
213 223
             $route['namespace'] = trim($route['namespace'],'/');
214
-            if($route['namespace'] == '')
215
-                $route['namespace'] = NULL;
224
+            if($route['namespace'] == '') {
225
+                            $route['namespace'] = NULL;
226
+            }
216 227
         }
217 228
 
218 229
         $route['middleware'] = array();
@@ -221,14 +232,14 @@  discard block
 block discarded – undo
221 232
         {
222 233
             if(is_array($attr['middleware']))
223 234
             {
224
-                foreach($attr['middleware'] as $middleware)
225
-                    $route['middleware'][] = $middleware; # Group
226
-            }
227
-            elseif( is_string($attr['middleware']))
235
+                foreach($attr['middleware'] as $middleware) {
236
+                                    $route['middleware'][] = $middleware;
237
+                }
238
+                # Group
239
+            } elseif( is_string($attr['middleware']))
228 240
             {
229 241
                 $route['middleware'][] = $attr['middleware']; # Group
230
-            }
231
-            else
242
+            } else
232 243
             {
233 244
                 show_error('Route middleware must be a string or an array',500,'Route error: bad middleware format');
234 245
             }
@@ -263,8 +274,7 @@  discard block
 block discarded – undo
263 274
         if(!$return)
264 275
         {
265 276
             self::$routes[] = (object) $route;
266
-        }
267
-        else
277
+        } else
268 278
         {
269 279
             return (object) $route;
270 280
         }
@@ -391,8 +401,9 @@  discard block
 block discarded – undo
391 401
      */
392 402
     public static function matches($verbs, $url, $attr, $hideOriginal = FALSE)
393 403
     {
394
-        if(!is_array($verbs))
395
-            show_error('Route::matches() first argument must be an array of valid HTTP Verbs', 500, 'Route error: bad Route::matches() verb list');
404
+        if(!is_array($verbs)) {
405
+                    show_error('Route::matches() first argument must be an array of valid HTTP Verbs', 500, 'Route error: bad Route::matches() verb list');
406
+        }
396 407
 
397 408
         foreach($verbs as $verb)
398 409
         {
@@ -429,17 +440,21 @@  discard block
 block discarded – undo
429 440
 
430 441
         $hideOriginal = FALSE;
431 442
 
432
-        if(isset($attr['namespace']))
433
-            $base_attr['namespace']  = $attr['namespace'];
443
+        if(isset($attr['namespace'])) {
444
+                    $base_attr['namespace']  = $attr['namespace'];
445
+        }
434 446
 
435
-        if(isset($attr['middleware']))
436
-            $base_attr['middleware'] = $attr['middleware'];
447
+        if(isset($attr['middleware'])) {
448
+                    $base_attr['middleware'] = $attr['middleware'];
449
+        }
437 450
 
438
-        if(isset($attr['hideOriginal']))
439
-            $hideOriginal = (bool) $attr['hideOriginal'];
451
+        if(isset($attr['hideOriginal'])) {
452
+                    $hideOriginal = (bool) $attr['hideOriginal'];
453
+        }
440 454
 
441
-        if(isset($attr['prefix']))
442
-            $base_attr['prefix']  = $attr['prefix'];
455
+        if(isset($attr['prefix'])) {
456
+                    $base_attr['prefix']  = $attr['prefix'];
457
+        }
443 458
 
444 459
         $only = array();
445 460
 
@@ -448,8 +463,7 @@  discard block
 block discarded – undo
448 463
             if(is_array($attr['only']))
449 464
             {
450 465
                 $only  = strtolower($attr['only']);
451
-            }
452
-            else
466
+            } else
453 467
             {
454 468
                 $only[] = strtolower($attr['only']);
455 469
             }
@@ -525,16 +539,19 @@  discard block
 block discarded – undo
525 539
 
526 540
         $path = $route->path;
527 541
 
528
-        if(!is_null($prefix))
529
-            $path = $prefix.'/'.$path;
542
+        if(!is_null($prefix)) {
543
+                    $path = $prefix.'/'.$path;
544
+        }
530 545
 
531
-        if(substr($path, 0, 1) == "/" && strlen($path) > 1)
532
-            $path = substr($path,1);
546
+        if(substr($path, 0, 1) == "/" && strlen($path) > 1) {
547
+                    $path = substr($path,1);
548
+        }
533 549
 
534 550
         $controller = $route->controller.'/'.$route->method;
535 551
 
536
-        if(!is_null($namespace))
537
-            $controller = $namespace.'/'.$controller;
552
+        if(!is_null($namespace)) {
553
+                    $controller = $namespace.'/'.$controller;
554
+        }
538 555
 
539 556
         $replaces =
540 557
             [
@@ -600,12 +617,14 @@  discard block
 block discarded – undo
600 617
             $path = key($route);
601 618
             $_404 = $route[$path];
602 619
 
603
-            if(!isset($routes[$path]))
604
-                $routes[$path] = $_404;
620
+            if(!isset($routes[$path])) {
621
+                            $routes[$path] = $_404;
622
+            }
605 623
         }
606 624
 
607
-        if(is_null(self::$defaultController))
608
-            show_error('You must specify a home route: Route::home() as default controller!', 500, 'Route error: missing default controller');
625
+        if(is_null(self::$defaultController)) {
626
+                    show_error('You must specify a home route: Route::home() as default controller!', 500, 'Route error: missing default controller');
627
+        }
609 628
 
610 629
         $defaultController = self::$defaultController->compiled;
611 630
         $defaultController = $defaultController[key($defaultController)];
@@ -615,8 +634,7 @@  discard block
 block discarded – undo
615 634
         if(is_null(self::$_404page))
616 635
         {
617 636
             $routes['404_override'] = '';
618
-        }
619
-        else
637
+        } else
620 638
         {
621 639
             $routes['404_override'] = self::$_404page->controller;
622 640
         }
@@ -639,11 +657,13 @@  discard block
 block discarded – undo
639 657
      */
640 658
     public static function group($attr, $routes)
641 659
     {
642
-        if(!is_array($attr))
643
-            show_error('Group attribute must be a valid array');
660
+        if(!is_array($attr)) {
661
+                    show_error('Group attribute must be a valid array');
662
+        }
644 663
 
645
-        if(!isset($attr['prefix']))
646
-            show_error('You must specify an prefix!');
664
+        if(!isset($attr['prefix'])) {
665
+                    show_error('You must specify an prefix!');
666
+        }
647 667
 
648 668
         self::$prefix = $attr['prefix'];
649 669
 
@@ -655,8 +675,7 @@  discard block
 block discarded – undo
655 675
         if(isset($attr['hideOriginals']) && $attr['hideOriginals'] === TRUE)
656 676
         {
657 677
             self::$hideOriginals = TRUE;
658
-        }
659
-        else
678
+        } else
660 679
         {
661 680
             self::$hideOriginals = FALSE;
662 681
         }
@@ -668,15 +687,14 @@  discard block
 block discarded – undo
668 687
                 //self::$middleware = $attr['middleware'];
669 688
                 if(is_array($attr['middleware']) && !empty($attr['middleware']))
670 689
                 {
671
-                    foreach($attr['middleware'] as $middleware)
672
-                        self::$groupMiddleware[] = [ $attr['prefix'] => $middleware ];
673
-                }
674
-                else
690
+                    foreach($attr['middleware'] as $middleware) {
691
+                                            self::$groupMiddleware[] = [ $attr['prefix'] => $middleware ];
692
+                    }
693
+                } else
675 694
                 {
676 695
                     self::$groupMiddleware[] = [ $attr['prefix'] => $attr['middleware'] ];
677 696
                 }
678
-            }
679
-            else
697
+            } else
680 698
             {
681 699
                 show_error('Group middleware not valid');
682 700
             }
@@ -691,8 +709,10 @@  discard block
 block discarded – undo
691 709
             $controller = $uri[0];
692 710
             $method = isset($uri[1]) ? $uri[1] : NULL;
693 711
 
694
-            if(self::$hideOriginals === TRUE)
695
-                self::$hiddenRoutes[] = [$controller => function(){ show_404(); }];
712
+            if(self::$hideOriginals === TRUE) {
713
+                            self::$hiddenRoutes[] = [$controller => function(){ show_404();
714
+            }
715
+            }];
696 716
 
697 717
             $route_attr['uses'] = $controller.( !is_null($method) ? '/'.$method : '');
698 718
             self::get('/', $route_attr);
@@ -727,14 +747,17 @@  discard block
 block discarded – undo
727 747
                 'as'   => $as
728 748
             ];
729 749
 
730
-        if(!is_null($attr) && !is_array($attr))
731
-            show_error('Default controller attributes must be an array',500,'Route error: bad attribute type');
750
+        if(!is_null($attr) && !is_array($attr)) {
751
+                    show_error('Default controller attributes must be an array',500,'Route error: bad attribute type');
752
+        }
732 753
 
733
-        if(!is_null($attr))
734
-            $routeAttr = array_merge($routeAttr,$attr);
754
+        if(!is_null($attr)) {
755
+                    $routeAttr = array_merge($routeAttr,$attr);
756
+        }
735 757
 
736
-        if(isset($attr['prefix']))
737
-            show_error('Default controller may not have a prefix!',500,'Route error: prefix not allowed');
758
+        if(isset($attr['prefix'])) {
759
+                    show_error('Default controller may not have a prefix!',500,'Route error: prefix not allowed');
760
+        }
738 761
 
739 762
         self::$defaultController = self::$routes[] = self::add('GET', '/', ['uses' => $controller, 'as' => $as],TRUE, TRUE);
740 763
     }
@@ -824,8 +847,9 @@  discard block
 block discarded – undo
824 847
     {
825 848
         foreach(self::$routes as $route)
826 849
         {
827
-            if($route->name == $search)
828
-                return base_url(self::compileRoute($route)->path);
850
+            if($route->name == $search) {
851
+                            return base_url(self::compileRoute($route)->path);
852
+            }
829 853
         }
830 854
 
831 855
         show_error('The route "'.$search.'" is not defined', 500, 'Route error');
@@ -850,14 +874,17 @@  discard block
 block discarded – undo
850 874
             $routes[$route->verb][] = $route;
851 875
         }
852 876
 
853
-        if(empty($routes))
854
-            return FALSE;
877
+        if(empty($routes)) {
878
+                    return FALSE;
879
+        }
855 880
 
856
-        if(is_null($requestMethod))
857
-            $requestMethod = $_SERVER['REQUEST_METHOD'];
881
+        if(is_null($requestMethod)) {
882
+                    $requestMethod = $_SERVER['REQUEST_METHOD'];
883
+        }
858 884
 
859
-        if(!isset($routes[$requestMethod]))
860
-            return FALSE;
885
+        if(!isset($routes[$requestMethod])) {
886
+                    return FALSE;
887
+        }
861 888
 
862 889
         $routes = $routes[$requestMethod];
863 890
 
@@ -877,8 +904,9 @@  discard block
 block discarded – undo
877 904
             {
878 905
                 $compiled = $route->compiled;
879 906
 
880
-                if($findPath == key($compiled))
881
-                    return $route;
907
+                if($findPath == key($compiled)) {
908
+                                    return $route;
909
+                }
882 910
             }
883 911
         }
884 912
 
Please login to merge, or discard this patch.
src/Middleware/Request.php 2 patches
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.
Braces   +17 added lines, -18 removed lines patch added patch discarded remove patch
@@ -64,20 +64,22 @@  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))
68
-            $formMethod = strtoupper($_POST['_method']);
67
+        if(isset($_POST['_method']) && in_array(strtoupper($_POST['_method']), $validMethods , TRUE)) {
68
+                    $formMethod = strtoupper($_POST['_method']);
69
+        }
69 70
 
70 71
         if(is_null($formMethod))
71 72
         {
72 73
             $this->requestMethod = $requestMethod;
73
-        }
74
-        else
74
+        } else
75 75
         {
76
-            if($requestMethod == 'POST')
77
-                $this->requestMethod = $formMethod;
76
+            if($requestMethod == 'POST') {
77
+                            $this->requestMethod = $formMethod;
78
+            }
78 79
 
79
-            if(!$this->CI->input->is_ajax_request() && $this->requestMethod == 'HEAD')
80
-                $this->requestMethod = 'POST';
80
+            if(!$this->CI->input->is_ajax_request() && $this->requestMethod == 'HEAD') {
81
+                            $this->requestMethod = 'POST';
82
+            }
81 83
         }
82 84
     }
83 85
 
@@ -92,22 +94,21 @@  discard block
 block discarded – undo
92 94
     {
93 95
         if(!$this->route)
94 96
         {
95
-            if(is_null(Route::get404()))
96
-                show_404();
97
+            if(is_null(Route::get404())) {
98
+                            show_404();
99
+            }
97 100
 
98 101
             if(Route::get404()->controller != get_class($this->CI))
99 102
             {
100 103
                 if(ENVIRONMENT != 'production')
101 104
                 {
102 105
                     show_error('The request method '.$this->requestMethod.' is not allowed to view the resource', 403, 'Forbidden method');
103
-                }
104
-                else
106
+                } else
105 107
                 {
106 108
                     redirect(Route::get404()->path);
107 109
                 }
108 110
             }
109
-        }
110
-        else
111
+        } else
111 112
         {
112 113
             if(method_exists($this->CI,$this->route->method))
113 114
             {
@@ -117,14 +118,12 @@  discard block
 block discarded – undo
117 118
 
118 119
                 $this->CI->output->_display();
119 120
                 exit(0);
120
-            }
121
-            else
121
+            } else
122 122
             {
123 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
-                }
127
-                else
126
+                } else
128 127
                 {
129 128
                     redirect(Route::get404()->path);
130 129
                 }
Please login to merge, or discard this patch.