@@ -4,11 +4,11 @@ |
||
4 | 4 | |
5 | 5 | use Exception; |
6 | 6 | |
7 | -class User{ |
|
7 | +class User { |
|
8 | 8 | |
9 | 9 | public function user_in() |
10 | 10 | { |
11 | - if(!array_key_exists('user',$_SESSION)){ |
|
11 | + if (!array_key_exists('user', $_SESSION)) { |
|
12 | 12 | throw new Exception('User must be logged in.'); |
13 | 13 | } |
14 | 14 | } |
@@ -2,6 +2,6 @@ |
||
2 | 2 | |
3 | 3 | use HnrAzevedo\Router\Router; |
4 | 4 | |
5 | -Router::get('/','Application:index')->filter('User:user_in'); |
|
5 | +Router::get('/', 'Application:index')->filter('User:user_in'); |
|
6 | 6 | |
7 | -Router::get('/{controller}/{method}','{controller}:{method}'); |
|
8 | 7 | \ No newline at end of file |
8 | +Router::get('/{controller}/{method}', '{controller}:{method}'); |
|
9 | 9 | \ No newline at end of file |
@@ -4,25 +4,25 @@ discard block |
||
4 | 4 | |
5 | 5 | use Exception; |
6 | 6 | |
7 | -trait CheckTrait{ |
|
7 | +trait CheckTrait { |
|
8 | 8 | use FilterTrait; |
9 | 9 | |
10 | 10 | protected function check_protocol(string $expected, string $current) |
11 | 11 | { |
12 | - if($expected !== $current){ |
|
13 | - throw new Exception('Page not found.',404); |
|
12 | + if ($expected !== $current) { |
|
13 | + throw new Exception('Page not found.', 404); |
|
14 | 14 | } |
15 | 15 | } |
16 | 16 | |
17 | - protected function check_name(string $route_name){ |
|
18 | - if(!array_key_exists($route_name,$this->routers)){ |
|
19 | - throw new Exception('Page not found.',404); |
|
17 | + protected function check_name(string $route_name) { |
|
18 | + if (!array_key_exists($route_name, $this->routers)) { |
|
19 | + throw new Exception('Page not found.', 404); |
|
20 | 20 | } |
21 | 21 | } |
22 | 22 | |
23 | 23 | protected function check_config() |
24 | 24 | { |
25 | - if(!defined('ROUTER_CONFIG')){ |
|
25 | + if (!defined('ROUTER_CONFIG')) { |
|
26 | 26 | throw new Exception("Information for loading routes has not been defined."); |
27 | 27 | } |
28 | 28 | } |
@@ -34,12 +34,12 @@ discard block |
||
34 | 34 | |
35 | 35 | protected function check_parameters(array $route_loop, array $route_request): bool |
36 | 36 | { |
37 | - foreach($route_loop as $rr => $param){ |
|
38 | - if( (substr($param,0,1) === '{') ){ |
|
39 | - $_GET[ substr($param,1,strlen($param)-2) ] = $route_request[$rr]; |
|
37 | + foreach ($route_loop as $rr => $param) { |
|
38 | + if ((substr($param, 0, 1) === '{')) { |
|
39 | + $_GET[substr($param, 1, strlen($param)-2)] = $route_request[$rr]; |
|
40 | 40 | } |
41 | 41 | |
42 | - if($this->check_parameter($param, $route_request[$rr])){ |
|
42 | + if ($this->check_parameter($param, $route_request[$rr])) { |
|
43 | 43 | return false; |
44 | 44 | } |
45 | 45 | } |
@@ -48,22 +48,22 @@ discard block |
||
48 | 48 | |
49 | 49 | protected function check_parameter(string $route_loop, string $route_request) |
50 | 50 | { |
51 | - return !( substr($route_loop,0,1) === '{' ) and $route_loop !== $route_request; |
|
51 | + return !(substr($route_loop, 0, 1) === '{') and $route_loop !== $route_request; |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | protected function check_role() |
55 | 55 | { |
56 | - if(!array_key_exists('role', $this->getData()['POST'])){ |
|
56 | + if (!array_key_exists('role', $this->getData()['POST'])) { |
|
57 | 57 | throw new Exception('O servidor não conseguiu identificar a finalidade deste formulário.'); |
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
61 | 61 | protected function hasProtocol(array $route, string $currentProtocol) |
62 | 62 | { |
63 | - $protocols = ( is_array($route['protocol']) ) ? $route['protocol'] : [ $route['protocol'] ]; |
|
63 | + $protocols = (is_array($route['protocol'])) ? $route['protocol'] : [$route['protocol']]; |
|
64 | 64 | |
65 | - foreach($protocols as $protocol){ |
|
66 | - if($protocol !== $currentProtocol){ |
|
65 | + foreach ($protocols as $protocol) { |
|
66 | + if ($protocol !== $currentProtocol) { |
|
67 | 67 | continue; |
68 | 68 | } |
69 | 69 | } |
@@ -4,13 +4,13 @@ discard block |
||
4 | 4 | |
5 | 5 | use Exception; |
6 | 6 | |
7 | -trait FilterTrait{ |
|
7 | +trait FilterTrait { |
|
8 | 8 | protected function check_filtering(array $route) |
9 | 9 | { |
10 | - $filters = (is_array($route['filters'])) ? $route['filters'] : [ $route['filters'] ]; |
|
10 | + $filters = (is_array($route['filters'])) ? $route['filters'] : [$route['filters']]; |
|
11 | 11 | |
12 | - foreach($filters as $filter){ |
|
13 | - if(is_null($filter)){ |
|
12 | + foreach ($filters as $filter) { |
|
13 | + if (is_null($filter)) { |
|
14 | 14 | continue; |
15 | 15 | } |
16 | 16 | $this->check_filter($filter); |
@@ -19,23 +19,23 @@ discard block |
||
19 | 19 | |
20 | 20 | protected function check_filter(string $filtername) |
21 | 21 | { |
22 | - if(count(explode(':',$filtername)) != 2){ |
|
22 | + if (count(explode(':', $filtername)) != 2) { |
|
23 | 23 | throw new Exception("Wrongly configured filter: {$filtername}."); |
24 | 24 | } |
25 | 25 | |
26 | - $filter = $this->check_filClassExist(explode(':',$filtername)[0]); |
|
27 | - $method = $this->check_filMethodExist($filter ,explode(':',$filtername)[1]); |
|
26 | + $filter = $this->check_filClassExist(explode(':', $filtername)[0]); |
|
27 | + $method = $this->check_filMethodExist($filter, explode(':', $filtername)[1]); |
|
28 | 28 | |
29 | 29 | $filter->$method(); |
30 | 30 | } |
31 | 31 | |
32 | 32 | protected function check_filClassExist(string $class) |
33 | 33 | { |
34 | - if(class_exists("Filter\\{$class}")){ |
|
34 | + if (class_exists("Filter\\{$class}")) { |
|
35 | 35 | $filter = "Filter\\{$class}"; |
36 | 36 | return new $filter(); |
37 | 37 | } |
38 | - if(file_exists(ROUTER_CONFIG['path.filters'].$class.'.php')){ |
|
38 | + if (file_exists(ROUTER_CONFIG['path.filters'].$class.'.php')) { |
|
39 | 39 | require_once(ROUTER_CONFIG['path.filters'].$class.'.php'); |
40 | 40 | $filter = "Filter\\{$class}"; |
41 | 41 | return new $filter(); |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | |
46 | 46 | protected function check_filMethodExist($filter, string $method): string |
47 | 47 | { |
48 | - if(!method_exists($filter, $method)){ |
|
48 | + if (!method_exists($filter, $method)) { |
|
49 | 49 | $filter = get_class(($filter)); |
50 | 50 | throw new Exception("Filter {$method} not found in {$filter}."); |
51 | 51 | } |