| @@ -27,9 +27,9 @@ discard block | ||
| 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 | ||
| 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(); | 
| @@ -29,7 +29,9 @@ discard block | ||
| 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 | ||
| 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 | |
| @@ -2,28 +2,28 @@ | ||
| 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'], |