Completed
Branch master (df5cd6)
by Marcos Sigueros
02:30
created
src/Router.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -27,9 +27,9 @@  discard block
 block discarded – undo
27 27
     public function dispatch($routes)
28 28
     {
29 29
         $result = null;
30
-        foreach($routes as $regex => $callable){
30
+        foreach ($routes as $regex => $callable) {
31 31
             $result = $this->execute($regex, $callable);
32
-            if($result !== false) return $result;
32
+            if ($result !== false) return $result;
33 33
         }
34 34
         return false;
35 35
     }
@@ -42,24 +42,24 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public function execute($regex, $callable)
44 44
     {
45
-        if(is_array($callable)){
45
+        if (is_array($callable)) {
46 46
             $callable = end($callable);
47
-            foreach($callable as $conf){
48
-                if($conf !== $_SERVER['REQUEST_METHOD']) return false;
47
+            foreach ($callable as $conf) {
48
+                if ($conf !== $_SERVER['REQUEST_METHOD']) return false;
49 49
             }
50 50
         }
51 51
         
52
-        if(preg_match('/^'.$regex.'$/', $this->base(), $matches)){
52
+        if (preg_match('/^'.$regex.'$/', $this->base(), $matches)) {
53 53
             
54 54
             array_shift($matches);
55 55
             
56
-            if(is_callable($callable)){
56
+            if (is_callable($callable)) {
57 57
                 return call_user_func_array($callable, $matches);
58 58
             }
59 59
             
60 60
             list($class, $method) = explode('@', $callable);
61 61
             
62
-            $method = !preg_match('/\@/', $callable) ? 'index' : $method ;
62
+            $method = !preg_match('/\@/', $callable) ? 'index' : $method;
63 63
             $class = class_exists($class) ? $class : $callable;
64 64
 
65 65
             $c = new $class();
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -29,7 +29,9 @@  discard block
 block discarded – undo
29 29
         $result = null;
30 30
         foreach($routes as $regex => $callable){
31 31
             $result = $this->execute($regex, $callable);
32
-            if($result !== false) return $result;
32
+            if($result !== false) {
33
+                return $result;
34
+            }
33 35
         }
34 36
         return false;
35 37
     }
@@ -45,7 +47,9 @@  discard block
 block discarded – undo
45 47
         if(is_array($callable)){
46 48
             $callable = end($callable);
47 49
             foreach($callable as $conf){
48
-                if($conf !== $_SERVER['REQUEST_METHOD']) return false;
50
+                if($conf !== $_SERVER['REQUEST_METHOD']) {
51
+                    return false;
52
+                }
49 53
             }
50 54
         }
51 55
         
Please login to merge, or discard this patch.
example/index.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -2,28 +2,28 @@
 block discarded – undo
2 2
 
3 3
 include('../vendor/autoload.php');
4 4
 
5
-class HomeController{
5
+class HomeController {
6 6
     
7
-    function index(){
7
+    function index() {
8 8
         return 'Hello people <form action="greeting/man" method="POST"><input type="Submit"></form>';
9 9
     }
10 10
     
11
-    function greet($a){
11
+    function greet($a) {
12 12
         return 'Hello '.$a;
13 13
     }
14 14
 
15 15
 }
16 16
 
17
-class BookController{
17
+class BookController {
18 18
     
19
-    function show($a){
19
+    function show($a) {
20 20
         return 'Book => '.$a;
21 21
     }
22 22
     
23 23
 }
24 24
 
25 25
 $routes = [
26
-    '\/annon' => ['GET', function(){
26
+    '\/annon' => ['GET', function() {
27 27
         return "Oh yeah callbacks :D";
28 28
     }],
29 29
     '\/greeting\/(.*)' => ['GET', 'HomeController@greet'],
Please login to merge, or discard this patch.