Passed
Push — master ( 3472d9...63f321 )
by Henri
01:18
created
examples/index.php 1 patch
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@
 block discarded – undo
11 11
     
12 12
     Router::create()->dispatch();
13 13
 
14
-}catch(Exception $er){
14
+} catch(Exception $er){
15 15
 
16 16
     die($er->getCode().'  -  '.$er->getMessage());
17 17
 
Please login to merge, or discard this patch.
src/Router.php 2 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -79,23 +79,23 @@  discard block
 block discarded – undo
79 79
 
80 80
     public function set($url , $role , $protocol = null): Router
81 81
     {
82
-		$url = (substr($url,0,1) !=='/' and strlen($url) > 0) ? "/{$url}" : $url;
82
+        $url = (substr($url,0,1) !=='/' and strlen($url) > 0) ? "/{$url}" : $url;
83 83
 
84
-    	foreach($this->routers as $key => $value){
85
-    		if( md5($this->prefix . $value['url'] . $value['protocol'] ) === md5( $url . $protocol ) ){
84
+        foreach($this->routers as $key => $value){
85
+            if( md5($this->prefix . $value['url'] . $value['protocol'] ) === md5( $url . $protocol ) ){
86 86
                 throw new Exception("There is already a route with the url {$url} and with the {$protocol} protocol configured.");
87 87
             }
88
-    	}
88
+        }
89 89
 
90
-		$route = [
91
-			'url' => $this->prefix.$url,
92
-			'role' => $role,
93
-			'protocol' => $protocol,
94
-			'filters' => null,
90
+        $route = [
91
+            'url' => $this->prefix.$url,
92
+            'role' => $role,
93
+            'protocol' => $protocol,
94
+            'filters' => null,
95 95
             'group' => self::getInstance()->group
96
-		];
96
+        ];
97 97
 
98
-		$this->routers[] = $route;		
98
+        $this->routers[] = $route;		
99 99
         
100 100
         return self::getInstance();
101 101
     }
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
             return $this->byName($route_name);
170 170
         }
171 171
 
172
-		$currentProtocol = $this->getProtocol();
172
+        $currentProtocol = $this->getProtocol();
173 173
 
174 174
         foreach(array_reverse($this->routers) as $r => $route){
175 175
             if(is_array($route['protocol'])){
@@ -178,13 +178,13 @@  discard block
 block discarded – undo
178 178
                         continue;
179 179
                     }
180 180
                 }
181
-	        }else{
182
-				if($route['protocol'] !== $currentProtocol){
181
+            }else{
182
+                if($route['protocol'] !== $currentProtocol){
183 183
                     continue;
184 184
                 }
185
-			}
185
+            }
186 186
 
187
-	        $route_loop = explode(
187
+            $route_loop = explode(
188 188
                 '/',
189 189
                 (substr($route['url'],strlen($route['url'])-1,1) === '/') 
190 190
                     ? substr($route['url'], 0, -1) 
@@ -193,45 +193,45 @@  discard block
 block discarded – undo
193 193
 
194 194
             /* ONLY FOR DEBUG CONDITION */
195 195
             $route_request = $route_loop;
196
-	        /*$route_request = explode(
196
+            /*$route_request = explode(
197 197
                 '/',
198 198
                 (substr($_SERVER['REQUEST_URI'],strlen($_SERVER['REQUEST_URI'])-1,1) === '/') 
199 199
                 ? substr($_SERVER['REQUEST_URI'], 0, -1) 
200 200
                 : $_SERVER['REQUEST_URI'] 
201 201
             );*/
202 202
 
203
-	        if(count($route_loop) !== count($route_request)){
203
+            if(count($route_loop) !== count($route_request)){
204 204
                 continue;
205 205
             }
206 206
 
207
-	        for($rr = 0; $rr < count($route_loop); $rr++){
208
-	            $param = (substr($route_loop[$rr],0,1)==='{');
207
+            for($rr = 0; $rr < count($route_loop); $rr++){
208
+                $param = (substr($route_loop[$rr],0,1)==='{');
209 209
 
210
-	            if($param){
210
+                if($param){
211 211
                     $param_name = substr($route_loop[$rr],1,strlen($route_loop[$rr])-2);
212
-	                $data[$param_name] = $route_request[$rr];
213
-	            }
212
+                    $data[$param_name] = $route_request[$rr];
213
+                }
214 214
 
215
-	            if(!$param and $route_loop[$rr] !== $route_request[$rr]){
215
+                if(!$param and $route_loop[$rr] !== $route_request[$rr]){
216 216
                     continue 2;
217 217
                 }
218
-	        }
219
-
220
-	        if(!empty($route['filters'])){
221
-	            if(is_array($route['filters'])){
222
-	                foreach($route['filters'] as $filter){
223
-	                    $this->filter->filtering($filter);
224
-	                }
225
-	            }else{
226
-	                $this->filter->filtering($route['filters']);
227
-	            }
228
-	        }
218
+            }
219
+
220
+            if(!empty($route['filters'])){
221
+                if(is_array($route['filters'])){
222
+                    foreach($route['filters'] as $filter){
223
+                        $this->filter->filtering($filter);
224
+                    }
225
+                }else{
226
+                    $this->filter->filtering($route['filters']);
227
+                }
228
+            }
229 229
 
230 230
             $this->Controller($route['role']);
231
-	        return true;
232
-	    }
231
+            return true;
232
+        }
233 233
 
234
-	    throw new Exception('Page not found.',404);
234
+        throw new Exception('Page not found.',404);
235 235
     }
236 236
 
237 237
     public static function filter($filters): Router
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
     }    
320 320
 
321 321
     public function ControllerForm($controller, string $method, array $values){
322
-		if(Validator::execute($values)){
322
+        if(Validator::execute($values)){
323 323
             if(!array_key_exists('role',$this->getData()['POST'])){
324 324
                 throw new Exception('O servidor não conseguiu identificar a finalidade deste formulário.');
325 325
             }
Please login to merge, or discard this patch.
Braces   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
                         continue;
167 167
                     }
168 168
                 }
169
-	        }else{
169
+	        } else{
170 170
 				if($route['protocol'] !== $currentProtocol){
171 171
                     continue;
172 172
                 }
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 	                foreach($route['filters'] as $filter){
211 211
 	                    $this->filter->filtering($filter);
212 212
 	                }
213
-	            }else{
213
+	            } else{
214 214
 	                $this->filter->filtering($route['filters']);
215 215
 	            }
216 216
 	        }
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
 
237 237
             }
238 238
             
239
-        }else{
239
+        } else{
240 240
             self::getInstance()->routers[count(self::getInstance()->routers)-1] = self::getInstance()->addFilter(end(self::getInstance()->routers),$filters);
241 241
         }
242 242
 
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
             foreach ($route['filters'] as $key => $value) {
257 257
                 $filters[] = $value;
258 258
             }
259
-        }else{
259
+        } else{
260 260
             $filters[] = $route['filters'];
261 261
         }
262 262
 
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 
293 293
         if( ( $this->getProtocol() == 'form') ){
294 294
             $this->ControllerForm($controller, $method, $data['POST']);
295
-        }else {
295
+        } else {
296 296
             $controller->$method($data);
297 297
         }
298 298
     }    
Please login to merge, or discard this patch.