@@ -4,18 +4,18 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | use Exception; |
| 6 | 6 | |
| 7 | -trait CheckWhere{ |
|
| 7 | +trait CheckWhere { |
|
| 8 | 8 | |
| 9 | 9 | protected function checkWhereParam($data) |
| 10 | 10 | { |
| 11 | - if(count($data) === 0){ |
|
| 11 | + if (count($data) === 0) { |
|
| 12 | 12 | throw new Exception('It is necessary to define a condition to be tested.'); |
| 13 | 13 | } |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | protected function checkWhereParams($params) |
| 17 | 17 | { |
| 18 | - if(count($params) === 0){ |
|
| 18 | + if (count($params) === 0) { |
|
| 19 | 19 | throw new Exception('The route in question has no parameters to be tested.'); |
| 20 | 20 | } |
| 21 | 21 | } |
@@ -24,24 +24,24 @@ discard block |
||
| 24 | 24 | { |
| 25 | 25 | $pass = true; |
| 26 | 26 | |
| 27 | - if(!is_array($route['where'])){ |
|
| 27 | + if (!is_array($route['where'])) { |
|
| 28 | 28 | return $pass; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - $routeURI = explode('/',$route['url']); |
|
| 31 | + $routeURI = explode('/', $route['url']); |
|
| 32 | 32 | $params = []; |
| 33 | - foreach($routeURI as $p => $part){ |
|
| 34 | - if(!$this->isParameter($part)){ |
|
| 33 | + foreach ($routeURI as $p => $part) { |
|
| 34 | + if (!$this->isParameter($part)) { |
|
| 35 | 35 | continue; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - $param = substr(str_replace('?','',$part),1,-1); |
|
| 38 | + $param = substr(str_replace('?', '', $part), 1, -1); |
|
| 39 | 39 | |
| 40 | - if(array_key_exists($param,$route['where'])){ |
|
| 40 | + if (array_key_exists($param, $route['where'])) { |
|
| 41 | 41 | |
| 42 | 42 | $params[$param] = $route['where'][$param]; |
| 43 | 43 | |
| 44 | - if(!preg_match("/^{$params[$param]}$/",$request[$p])){ |
|
| 44 | + if (!preg_match("/^{$params[$param]}$/", $request[$p])) { |
|
| 45 | 45 | $pass = false; |
| 46 | 46 | } |
| 47 | 47 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | protected function isParameter(string $part): bool |
| 54 | 54 | { |
| 55 | - return (substr($part,0,1) === '{' && substr($part,-1) === '}'); |
|
| 55 | + return (substr($part, 0, 1) === '{' && substr($part, -1) === '}'); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | protected function callWhereAdd($data) |
@@ -62,16 +62,16 @@ discard block |
||
| 62 | 62 | $data = (count($data) > 1) ? [$data[0] => $data[1]] : $data[0]; |
| 63 | 63 | |
| 64 | 64 | $route = end($this->routers); |
| 65 | - $routeURI = explode('/',$route['url']); |
|
| 65 | + $routeURI = explode('/', $route['url']); |
|
| 66 | 66 | $params = []; |
| 67 | - foreach($routeURI as $part){ |
|
| 68 | - if(!$this->isParameter($part)){ |
|
| 67 | + foreach ($routeURI as $part) { |
|
| 68 | + if (!$this->isParameter($part)) { |
|
| 69 | 69 | continue; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - $param = substr(str_replace('?','',$part),1,-1); |
|
| 72 | + $param = substr(str_replace('?', '', $part), 1, -1); |
|
| 73 | 73 | |
| 74 | - if(array_key_exists($param,$data)){ |
|
| 74 | + if (array_key_exists($param, $data)) { |
|
| 75 | 75 | $params[$param] = $data[$param]; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | |
| 80 | 80 | $this->checkWhereParams($params); |
| 81 | 81 | |
| 82 | - $route['where'] = (is_array($route['where'])) ? array_merge($route['where'],$params) : $params; |
|
| 82 | + $route['where'] = (is_array($route['where'])) ? array_merge($route['where'], $params) : $params; |
|
| 83 | 83 | |
| 84 | 84 | $this->routers[count($this->routers)-1] = $route; |
| 85 | 85 | } |