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