@@ -66,9 +66,9 @@ discard block |
||
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | $routes[$index] = [ |
| 69 | - 'uri' => new Uri(self::getInstance()->getHost().self::getInstance()->getPrefix().$uri), |
|
| 70 | - 'action' => $closure, |
|
| 71 | - 'method' => strtoupper($method), |
|
| 69 | + 'uri' => new Uri(self::getInstance()->getHost().self::getInstance()->getPrefix().$uri), |
|
| 70 | + 'action' => $closure, |
|
| 71 | + 'method' => strtoupper($method), |
|
| 72 | 72 | 'middlewares' => [], |
| 73 | 73 | 'where' => [], |
| 74 | 74 | 'before' => [], |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | private static function checkDuplicity(string $uri, string $method): void |
| 87 | 87 | { |
| 88 | 88 | foreach(self::getInstance()->getRoutes() as $route){ |
| 89 | - if( md5($route['uri'].$route['method']) === md5($uri.$method) ){ |
|
| 89 | + if( md5($route['uri'].$route['method']) === md5($uri.$method) ){ |
|
| 90 | 90 | throw new \RuntimeException("There is already a route with the URI {$uri} and with the {$method} METHOD configured."); |
| 91 | 91 | } |
| 92 | 92 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace HnrAzevedo\Router; |
| 6 | 6 | |
@@ -12,32 +12,32 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | public static function get(string $uri, $closure): RouterInterface |
| 14 | 14 | { |
| 15 | - return self::set('get',$uri,$closure); |
|
| 15 | + return self::set('get', $uri, $closure); |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | public static function post(string $uri, $closure): RouterInterface |
| 19 | 19 | { |
| 20 | - return self::set('post',$uri,$closure); |
|
| 20 | + return self::set('post', $uri, $closure); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | public static function ajax(string $uri, $closure): RouterInterface |
| 24 | 24 | { |
| 25 | - return self::set('ajax',$uri,$closure); |
|
| 25 | + return self::set('ajax', $uri, $closure); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | public static function delete(string $uri, $closure): RouterInterface |
| 29 | 29 | { |
| 30 | - return self::set('delete',$uri,$closure); |
|
| 30 | + return self::set('delete', $uri, $closure); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | public static function put(string $uri, $closure): RouterInterface |
| 34 | 34 | { |
| 35 | - return self::set('put',$uri,$closure); |
|
| 35 | + return self::set('put', $uri, $closure); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | public static function patch(string $uri, $closure): RouterInterface |
| 39 | 39 | { |
| 40 | - return self::set('patch',$uri,$closure); |
|
| 40 | + return self::set('patch', $uri, $closure); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | public static function match(string $method, string $uri, $closure): RouterInterface |
@@ -48,20 +48,20 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | public static function any(string $uri, $closure): RouterInterface |
| 50 | 50 | { |
| 51 | - return self::set('*',$uri,$closure); |
|
| 51 | + return self::set('*', $uri, $closure); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | private static function set(string $method, string $uri, $closure): RouterInterface |
| 55 | 55 | { |
| 56 | - $uri = (substr($uri,0,1) !=='/' and strlen($uri) > 0) ? "/{$uri}" : $uri; |
|
| 56 | + $uri = (substr($uri, 0, 1) !== '/' and strlen($uri) > 0) ? "/{$uri}" : $uri; |
|
| 57 | 57 | |
| 58 | - self::checkDuplicity($uri,$method); |
|
| 58 | + self::checkDuplicity($uri, $method); |
|
| 59 | 59 | |
| 60 | 60 | $routes = self::getInstance()->getRoutes(); |
| 61 | 61 | |
| 62 | 62 | $index = sha1(date('d/m/Y H:i:s').count($routes)); |
| 63 | 63 | |
| 64 | - while(array_key_exists($index,$routes)){ |
|
| 64 | + while (array_key_exists($index, $routes)) { |
|
| 65 | 65 | $index = sha1(date('d/m/Y H:i:s').rand(count($routes))); |
| 66 | 66 | } |
| 67 | 67 | |
@@ -85,8 +85,8 @@ discard block |
||
| 85 | 85 | |
| 86 | 86 | private static function checkDuplicity(string $uri, string $method): void |
| 87 | 87 | { |
| 88 | - foreach(self::getInstance()->getRoutes() as $route){ |
|
| 89 | - if( md5($route['uri'].$route['method']) === md5($uri.$method) ){ |
|
| 88 | + foreach (self::getInstance()->getRoutes() as $route) { |
|
| 89 | + if (md5($route['uri'].$route['method']) === md5($uri.$method)) { |
|
| 90 | 90 | throw new \RuntimeException("There is already a route with the URI {$uri} and with the {$method} METHOD configured."); |
| 91 | 91 | } |
| 92 | 92 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace HnrAzevedo\Router; |
| 6 | 6 | |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | { |
| 22 | 22 | $this->hasRouteName($name); |
| 23 | 23 | |
| 24 | - if(!$this->loaded){ |
|
| 24 | + if (!$this->loaded) { |
|
| 25 | 25 | $this->loadIn($name); |
| 26 | 26 | } |
| 27 | 27 | |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | public function hasCurrentRoute(): void |
| 32 | 32 | { |
| 33 | - if(!isset($this->currentRoute)){ |
|
| 33 | + if (!isset($this->currentRoute)) { |
|
| 34 | 34 | throw new \RuntimeException('Route not yet loaded'); |
| 35 | 35 | } |
| 36 | 36 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace HnrAzevedo\Router; |
| 6 | 6 | |