@@ -2,13 +2,13 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace HnrAzevedo\Router; |
4 | 4 | |
5 | -trait Helper{ |
|
5 | +trait Helper { |
|
6 | 6 | use CheckTrait, ControllerTrait; |
7 | 7 | |
8 | 8 | protected function getProtocol(): string |
9 | 9 | { |
10 | 10 | $protocol = ((isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')) ? 'ajax' : 'get'; |
11 | - $protocol = (array_key_existS('REQUEST_METHOD',$_SESSION)) ? strtolower($_SERVER['REQUEST_METHOD']) : $protocol; |
|
11 | + $protocol = (array_key_existS('REQUEST_METHOD', $_SESSION)) ? strtolower($_SERVER['REQUEST_METHOD']) : $protocol; |
|
12 | 12 | |
13 | 13 | return $protocol; |
14 | 14 | } |
@@ -26,13 +26,13 @@ discard block |
||
26 | 26 | protected function import(string $path) |
27 | 27 | { |
28 | 28 | foreach (scandir($path) as $routeFile) { |
29 | - if(pathinfo($path.DIRECTORY_SEPARATOR.$routeFile, PATHINFO_EXTENSION) === 'php'){ |
|
30 | - require_once($path. DIRECTORY_SEPARATOR .$routeFile); |
|
29 | + if (pathinfo($path.DIRECTORY_SEPARATOR.$routeFile, PATHINFO_EXTENSION) === 'php') { |
|
30 | + require_once($path.DIRECTORY_SEPARATOR.$routeFile); |
|
31 | 31 | } |
32 | 32 | } |
33 | 33 | } |
34 | 34 | |
35 | - protected function ControllerForm($controller, string $method, array $values){ |
|
35 | + protected function ControllerForm($controller, string $method, array $values) { |
|
36 | 36 | $this->check_role(); |
37 | 37 | $role = ($method !== 'method') ? $method : $this->getData()['POST']['role']; |
38 | 38 | $data = (!is_null($values)) ? json_decode($values['data']) : null; |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $data = $this->getData(); |
45 | 45 | |
46 | 46 | foreach ($data['GET'] as $name => $value) { |
47 | - $controll = str_replace('{'.$name.'}',$value,$controll); |
|
47 | + $controll = str_replace('{'.$name.'}', $value, $controll); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | $this->check_controllsettable($controll); |
@@ -53,11 +53,11 @@ discard block |
||
53 | 53 | |
54 | 54 | $this->check_controllmethod($controll); |
55 | 55 | |
56 | - $controller = ROUTER_CONFIG['controller.namespace'].'\\'. ucfirst(explode(':',$controll)[0]); |
|
56 | + $controller = ROUTER_CONFIG['controller.namespace'].'\\'.ucfirst(explode(':', $controll)[0]); |
|
57 | 57 | $controller = new $controller(); |
58 | - $method = explode(':',$controll)[1]; |
|
58 | + $method = explode(':', $controll)[1]; |
|
59 | 59 | |
60 | - if( ( $this->getProtocol() == 'form') ){ |
|
60 | + if (($this->getProtocol() == 'form')) { |
|
61 | 61 | $this->ControllerForm($controller, $method, $data['POST']); |
62 | 62 | }else { |
63 | 63 | $controller->$method($data); |
@@ -66,12 +66,12 @@ discard block |
||
66 | 66 | |
67 | 67 | protected function explodeRoute(bool $bar, string $url): array |
68 | 68 | { |
69 | - return explode( '/', $bar ? substr($url, 0, -1) : $url ); |
|
69 | + return explode('/', $bar ? substr($url, 0, -1) : $url); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | protected function toHiking($walking) |
73 | 73 | { |
74 | - if(is_string($walking)){ |
|
74 | + if (is_string($walking)) { |
|
75 | 75 | $this->Controller($walking); |
76 | 76 | return true; |
77 | 77 | } |