@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | use Exception; |
| 6 | 6 | |
| 7 | -trait CheckTrait{ |
|
| 7 | +trait CheckTrait { |
|
| 8 | 8 | use FilterTrait, CheckWhere; |
| 9 | 9 | |
| 10 | 10 | protected function checkProtocol(string $expected, string $current): bool |
@@ -12,14 +12,14 @@ discard block |
||
| 12 | 12 | return (strtoupper($expected) === strtoupper($current)); |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | - protected function checkName(string $routeName){ |
|
| 16 | - if(!array_key_exists($routeName,$this->routers)){ |
|
| 15 | + protected function checkName(string $routeName) { |
|
| 16 | + if (!array_key_exists($routeName, $this->routers)) { |
|
| 17 | 17 | throw new Exception('Page not found.', 404); |
| 18 | 18 | } |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | - protected function checkTypeRole($role){ |
|
| 22 | - if(!is_string($role) && @get_class($role) !== 'Closure' ){ |
|
| 21 | + protected function checkTypeRole($role) { |
|
| 22 | + if (!is_string($role) && @get_class($role) !== 'Closure') { |
|
| 23 | 23 | throw new Exception("Improperly defined route track."); |
| 24 | 24 | } |
| 25 | 25 | } |
@@ -31,12 +31,12 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | protected function checkParameters(array $routeLoop, array $routeRequest): bool |
| 33 | 33 | { |
| 34 | - foreach($routeLoop as $rr => $param){ |
|
| 35 | - if( (substr($param,0,1) === '{') ){ |
|
| 36 | - $_GET[ substr($param,1,strlen($param)-2) ] = $routeRequest[$rr]; |
|
| 34 | + foreach ($routeLoop as $rr => $param) { |
|
| 35 | + if ((substr($param, 0, 1) === '{')) { |
|
| 36 | + $_GET[substr($param, 1, strlen($param)-2)] = $routeRequest[$rr]; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - if($this->checkParameter($param, $routeRequest[$rr])){ |
|
| 39 | + if ($this->checkParameter($param, $routeRequest[$rr])) { |
|
| 40 | 40 | return false; |
| 41 | 41 | } |
| 42 | 42 | } |
@@ -45,22 +45,22 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | protected function checkParameter(string $routeLoop, string $routeRequest) |
| 47 | 47 | { |
| 48 | - return !( substr($routeLoop,0,1) === '{' ) and $routeLoop !== $routeRequest; |
|
| 48 | + return !(substr($routeLoop, 0, 1) === '{') and $routeLoop !== $routeRequest; |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | protected function checkRole() |
| 52 | 52 | { |
| 53 | - if(!array_key_exists('role', $this->getData()['POST'])){ |
|
| 53 | + if (!array_key_exists('role', $this->getData()['POST'])) { |
|
| 54 | 54 | throw new Exception('O servidor não conseguiu identificar a finalidade deste formulário.'); |
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | protected function hasProtocol(array $route, string $currentProtocol) |
| 59 | 59 | { |
| 60 | - $protocols = ( is_array($route['protocol']) ) ? $route['protocol'] : [ $route['protocol'] ]; |
|
| 60 | + $protocols = (is_array($route['protocol'])) ? $route['protocol'] : [$route['protocol']]; |
|
| 61 | 61 | |
| 62 | - foreach($protocols as $protocol){ |
|
| 63 | - if(strtoupper($protocol) !== strtoupper($currentProtocol)){ |
|
| 62 | + foreach ($protocols as $protocol) { |
|
| 63 | + if (strtoupper($protocol) !== strtoupper($currentProtocol)) { |
|
| 64 | 64 | continue; |
| 65 | 65 | } |
| 66 | 66 | } |
@@ -68,9 +68,9 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | protected function checkToHiking($route, $routeRequest, $routeLoop): bool |
| 70 | 70 | { |
| 71 | - if($this->checkNumparams($routeLoop, $routeRequest) || |
|
| 71 | + if ($this->checkNumparams($routeLoop, $routeRequest) || |
|
| 72 | 72 | !$this->checkParameters($routeLoop, $routeRequest) || |
| 73 | - !$this->checkWhere($route, $routeRequest)){ |
|
| 73 | + !$this->checkWhere($route, $routeRequest)) { |
|
| 74 | 74 | return false; |
| 75 | 75 | } |
| 76 | 76 | return true; |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | |
| 79 | 79 | protected function hasRouteName(string $name): void |
| 80 | 80 | { |
| 81 | - if(array_key_exists($name, $this->routers)){ |
|
| 81 | + if (array_key_exists($name, $this->routers)) { |
|
| 82 | 82 | throw new Exception("There is already a route with the name {$name} configured."); |
| 83 | 83 | } |
| 84 | 84 | } |
@@ -4,28 +4,28 @@ |
||
| 4 | 4 | |
| 5 | 5 | use Exception; |
| 6 | 6 | |
| 7 | -trait ControllerTrait{ |
|
| 7 | +trait ControllerTrait { |
|
| 8 | 8 | |
| 9 | 9 | protected function checkControllsettable(string $controll) |
| 10 | 10 | { |
| 11 | - if(count(explode(':',$controll)) != 2){ |
|
| 11 | + if (count(explode(':', $controll)) != 2) { |
|
| 12 | 12 | throw new Exception("Controller {$controll} badly set."); |
| 13 | 13 | } |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | protected function checkControllexist(string $controll) |
| 17 | 17 | { |
| 18 | - $controllname = ucfirst(explode(':',$controll)[0]); |
|
| 19 | - if(!class_exists($controllname)){ |
|
| 18 | + $controllname = ucfirst(explode(':', $controll)[0]); |
|
| 19 | + if (!class_exists($controllname)) { |
|
| 20 | 20 | throw new Exception("No controller {$controllname} found."); |
| 21 | 21 | } |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | protected function checkControllmethod(string $controll) |
| 25 | 25 | { |
| 26 | - $controllname = ucfirst(explode(':',$controll)[0]); |
|
| 27 | - $method = explode(':',$controll)[1]; |
|
| 28 | - if(!method_exists($controllname, $method)){ |
|
| 26 | + $controllname = ucfirst(explode(':', $controll)[0]); |
|
| 27 | + $method = explode(':', $controll)[1]; |
|
| 28 | + if (!method_exists($controllname, $method)) { |
|
| 29 | 29 | throw new Exception("No method {$method} found for {$controllname}."); |
| 30 | 30 | } |
| 31 | 31 | } |
@@ -3,21 +3,21 @@ |
||
| 3 | 3 | use HnrAzevedo\Router\Router; |
| 4 | 4 | |
| 5 | 5 | /* Returning parameters passed via URL in anonymous functions */ |
| 6 | -Router::get('/{parameter}/{otherparameter}', function($parameter, $otherparameter){ |
|
| 6 | +Router::get('/{parameter}/{otherparameter}', function($parameter, $otherparameter) { |
|
| 7 | 7 | echo "Parameter 1:{$parameter}, Parameter 2:{$otherparameter}."; |
| 8 | 8 | }); |
| 9 | 9 | |
| 10 | 10 | /* Passing controller and/or method via parameter in URL */ |
| 11 | -Router::get('/{controller}/{method}','{controller}:{method}'); |
|
| 12 | -Router::get('/{controller}/{method}','{controller}:method'); |
|
| 11 | +Router::get('/{controller}/{method}', '{controller}:{method}'); |
|
| 12 | +Router::get('/{controller}/{method}', '{controller}:method'); |
|
| 13 | 13 | |
| 14 | 14 | /* Passing value via parameter */ |
| 15 | -Router::get('/my-account/{teste}','Controller\\User:my_account'); |
|
| 15 | +Router::get('/my-account/{teste}', 'Controller\\User:my_account'); |
|
| 16 | 16 | |
| 17 | 17 | /* Filter example */ |
| 18 | -Router::get('/my-account','Controller\\User:my_account')->filter('Filter\\User:user_in'); |
|
| 18 | +Router::get('/my-account', 'Controller\\User:my_account')->filter('Filter\\User:user_in'); |
|
| 19 | 19 | |
| 20 | 20 | /* Accessed by all protocols */ |
| 21 | -Router::any('/',function(){ |
|
| 21 | +Router::any('/', function() { |
|
| 22 | 22 | // |
| 23 | 23 | }); |