@@ -4,25 +4,25 @@ 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 checkExistParam($param, $data) |
17 | 17 | { |
18 | - if(!array_key_exists($param,$data)){ |
|
18 | + if (!array_key_exists($param, $data)) { |
|
19 | 19 | throw new Exception('Test parameter not available on the route in question.'); |
20 | 20 | } |
21 | 21 | } |
22 | 22 | |
23 | 23 | protected function checkWhereParams($params) |
24 | 24 | { |
25 | - if(count($params) === 0){ |
|
25 | + if (count($params) === 0) { |
|
26 | 26 | throw new Exception('The route in question has no parameters to be tested.'); |
27 | 27 | } |
28 | 28 | } |
@@ -31,18 +31,18 @@ discard block |
||
31 | 31 | { |
32 | 32 | $pass = true; |
33 | 33 | |
34 | - if(!is_array($route['where'])){ |
|
34 | + if (!is_array($route['where'])) { |
|
35 | 35 | return $pass; |
36 | 36 | } |
37 | 37 | |
38 | - $routeURI = explode('/',$route['url']); |
|
38 | + $routeURI = explode('/', $route['url']); |
|
39 | 39 | $params = []; |
40 | - foreach($routeURI as $p => $part){ |
|
41 | - if(substr($part,0,1) === '{' && substr($part,-1) === '}'){ |
|
42 | - $param = substr($part,1,-1); |
|
40 | + foreach ($routeURI as $p => $part) { |
|
41 | + if (substr($part, 0, 1) === '{' && substr($part, -1) === '}') { |
|
42 | + $param = substr($part, 1, -1); |
|
43 | 43 | $params[$param] = $route['where'][$param]; |
44 | 44 | |
45 | - if(!preg_match("/^{$params[$param]}$/",$request[$p])){ |
|
45 | + if (!preg_match("/^{$params[$param]}$/", $request[$p])) { |
|
46 | 46 | $pass = false; |
47 | 47 | } |
48 | 48 | } |
@@ -58,13 +58,13 @@ discard block |
||
58 | 58 | $data = (count($data) > 1) ? [$data[0] => $data[1]] : $data[0]; |
59 | 59 | |
60 | 60 | $route = end($this->routers); |
61 | - $routeURI = explode('/',$route['url']); |
|
61 | + $routeURI = explode('/', $route['url']); |
|
62 | 62 | $params = []; |
63 | - foreach($routeURI as $part){ |
|
64 | - if(substr($part,0,1) === '{' && substr($part,-1) === '}'){ |
|
65 | - $param = substr($part,1,-1); |
|
63 | + foreach ($routeURI as $part) { |
|
64 | + if (substr($part, 0, 1) === '{' && substr($part, -1) === '}') { |
|
65 | + $param = substr($part, 1, -1); |
|
66 | 66 | |
67 | - $this->checkExistParam($param,$data); |
|
67 | + $this->checkExistParam($param, $data); |
|
68 | 68 | |
69 | 69 | $params[$param] = $data[$param]; |
70 | 70 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | |
73 | 73 | $this->checkWhereParams($params); |
74 | 74 | |
75 | - $route['where'] = (is_array($route['where'])) ? array_merge($route['where'],$params) : $params; |
|
75 | + $route['where'] = (is_array($route['where'])) ? array_merge($route['where'], $params) : $params; |
|
76 | 76 | |
77 | 77 | $this->routers[count($this->routers)-1] = $route; |
78 | 78 | } |