@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | |
16 | 16 | protected function getState(string $state, bool $except = false) |
17 | 17 | { |
18 | - if($state === 'before'){ |
|
18 | + if ($state === 'before') { |
|
19 | 19 | return ($except) ? $this->beforeExcepts : $this->beforeAll; |
20 | 20 | } |
21 | 21 | |
@@ -24,8 +24,8 @@ discard block |
||
24 | 24 | |
25 | 25 | protected function setState(string $state, $settable, bool $except = false): bool |
26 | 26 | { |
27 | - if($state === 'before'){ |
|
28 | - if($except){ |
|
27 | + if ($state === 'before') { |
|
28 | + if ($except) { |
|
29 | 29 | $this->beforeExcepts = $settable; |
30 | 30 | return true; |
31 | 31 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | return true; |
35 | 35 | } |
36 | 36 | |
37 | - if($except){ |
|
37 | + if ($except) { |
|
38 | 38 | $this->afterExcepts = $settable; |
39 | 39 | return true; |
40 | 40 | } |
@@ -45,24 +45,24 @@ discard block |
||
45 | 45 | |
46 | 46 | public static function before($closure): RouterInterface |
47 | 47 | { |
48 | - return self::addInRoute('before',$closure); |
|
48 | + return self::addInRoute('before', $closure); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | public static function after($closure): RouterInterface |
52 | 52 | { |
53 | - return self::addInRoute('after',$closure); |
|
53 | + return self::addInRoute('after', $closure); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | public static function beforeAll($closure, $excepts): RouterInterface |
57 | 57 | { |
58 | - self::getInstance()->setState('before', (is_array($excepts)) ? $excepts : [ $excepts ] ,true); |
|
58 | + self::getInstance()->setState('before', (is_array($excepts)) ? $excepts : [$excepts], true); |
|
59 | 59 | self::getInstance()->setState('before', $closure, false); |
60 | 60 | return self::getInstance(); |
61 | 61 | } |
62 | 62 | |
63 | 63 | public static function afterAll($closure, $excepts): RouterInterface |
64 | 64 | { |
65 | - self::getInstance()->setState('after', (is_array($excepts)) ? $excepts : [ $excepts ] ,true); |
|
65 | + self::getInstance()->setState('after', (is_array($excepts)) ? $excepts : [$excepts], true); |
|
66 | 66 | self::getInstance()->setState('after', $closure, false); |
67 | 67 | return self::getInstance(); |
68 | 68 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | |
80 | 80 | protected function executeRouteAction(): bool |
81 | 81 | { |
82 | - if(is_callable($this->current()['action'])){ |
|
82 | + if (is_callable($this->current()['action'])) { |
|
83 | 83 | call_user_func_array($this->current()['action'], $_REQUEST); |
84 | 84 | return true; |
85 | 85 | } |
@@ -91,12 +91,12 @@ discard block |
||
91 | 91 | private static function addInRoutes(string $state, $closure, $excepts): RouterInterface |
92 | 92 | { |
93 | 93 | self::getInstance()->isInPseudGroup(); |
94 | - $excepts = (is_array($excepts)) ? $excepts : [ $excepts ]; |
|
94 | + $excepts = (is_array($excepts)) ? $excepts : [$excepts]; |
|
95 | 95 | $group = self::getInstance()->inSave()['group']; |
96 | 96 | |
97 | - foreach(self::getInstance()->getRoutes() as $r => $route){ |
|
98 | - if($route['group'] === $group && !in_array($r,$excepts)){ |
|
99 | - self::getInstance()->getRoutes()[$r][$state] = (is_null($route[$state])) ? [ $closure ] : array_merge($route[$state], [ $closure ]); |
|
97 | + foreach (self::getInstance()->getRoutes() as $r => $route) { |
|
98 | + if ($route['group'] === $group && !in_array($r, $excepts)) { |
|
99 | + self::getInstance()->getRoutes()[$r][$state] = (is_null($route[$state])) ? [$closure] : array_merge($route[$state], [$closure]); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
@@ -106,14 +106,14 @@ discard block |
||
106 | 106 | private static function addInRoute(string $state, $closure): RouterInterface |
107 | 107 | { |
108 | 108 | $route = self::getInstance()->inSave(); |
109 | - $route[$state] = (!is_null($route[$state])) ? [ $closure ] : array_merge($route[$state], [ $closure ]); |
|
110 | - self::updateRoute($route,array_key_last(self::getInstance()->getRoutes())); |
|
109 | + $route[$state] = (!is_null($route[$state])) ? [$closure] : array_merge($route[$state], [$closure]); |
|
110 | + self::updateRoute($route, array_key_last(self::getInstance()->getRoutes())); |
|
111 | 111 | return self::getInstance(); |
112 | 112 | } |
113 | 113 | |
114 | 114 | protected function executeBefore(): void |
115 | 115 | { |
116 | - if(!in_array($this->currentName(), (array) $this->getState('before', true))){ |
|
116 | + if (!in_array($this->currentName(), (array) $this->getState('before', true))) { |
|
117 | 117 | ($this->getState('before', false))(); |
118 | 118 | } |
119 | 119 | |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | |
123 | 123 | protected function executeAfter(): void |
124 | 124 | { |
125 | - if(!in_array($this->currentName(), (array) $this->getState('after', true))){ |
|
125 | + if (!in_array($this->currentName(), (array) $this->getState('after', true))) { |
|
126 | 126 | ($this->getState('after', false))(); |
127 | 127 | } |
128 | 128 | |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | |
132 | 132 | private function executeState(string $stage): void |
133 | 133 | { |
134 | - foreach($this->current()[$stage] as $state){ |
|
135 | - if(is_callable($state)){ |
|
134 | + foreach ($this->current()[$stage] as $state) { |
|
135 | + if (is_callable($state)) { |
|
136 | 136 | $state(); |
137 | 137 | continue; |
138 | 138 | } |
@@ -143,31 +143,31 @@ discard block |
||
143 | 143 | |
144 | 144 | private function executeController(string $controllerMeth): void |
145 | 145 | { |
146 | - if(count(explode('@',$controllerMeth)) !== 2){ |
|
146 | + if (count(explode('@', $controllerMeth)) !== 2) { |
|
147 | 147 | $path = urldecode($this->current()['uri']->getPath()); |
148 | 148 | throw new \RuntimeException("Misconfigured route action ({$path})"); |
149 | 149 | } |
150 | 150 | |
151 | - $controller = (string) explode('@',$controllerMeth)[0]; |
|
152 | - $method = (string) explode('@',$controllerMeth)[1]; |
|
151 | + $controller = (string) explode('@', $controllerMeth)[0]; |
|
152 | + $method = (string) explode('@', $controllerMeth)[1]; |
|
153 | 153 | |
154 | 154 | $this->checkControllerMeth($controllerMeth); |
155 | 155 | |
156 | - call_user_func_array([(new $controller()),$method], $_REQUEST); |
|
156 | + call_user_func_array([(new $controller()), $method], $_REQUEST); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | private function checkControllerMeth(string $controllerMeth): void |
160 | 160 | { |
161 | - $routeURI = str_replace(['{:','{','}'],'',urldecode($this->current()['uri']->getPath())); |
|
161 | + $routeURI = str_replace(['{:', '{', '}'], '', urldecode($this->current()['uri']->getPath())); |
|
162 | 162 | |
163 | - $controller = (string) explode('@',$controllerMeth)[0]; |
|
164 | - $method = (string) explode('@',$controllerMeth)[1]; |
|
163 | + $controller = (string) explode('@', $controllerMeth)[0]; |
|
164 | + $method = (string) explode('@', $controllerMeth)[1]; |
|
165 | 165 | |
166 | - if(!class_exists($controller)){ |
|
166 | + if (!class_exists($controller)) { |
|
167 | 167 | throw new \RuntimeException("Controller not found in route URI {$routeURI}"); |
168 | 168 | } |
169 | 169 | |
170 | - if(!method_exists($controller, $method)){ |
|
170 | + if (!method_exists($controller, $method)) { |
|
171 | 171 | throw new \RuntimeException("Method {$method} not found in controller {$controller} in route URI {$routeURI}"); |
172 | 172 | } |
173 | 173 |
@@ -2,7 +2,7 @@ |
||
2 | 2 | |
3 | 3 | namespace HnrAzevedo\Router; |
4 | 4 | |
5 | -trait CurrentTrait{ |
|
5 | +trait CurrentTrait { |
|
6 | 6 | use Helper; |
7 | 7 | |
8 | 8 | protected array $currentRoute = []; |