@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace HnrAzevedo\Router; |
6 | 6 | |
@@ -22,9 +22,9 @@ discard block |
||
22 | 22 | |
23 | 23 | public static function globalMiddlewares(?array $middlewares = null): array |
24 | 24 | { |
25 | - if(null !== $middlewares) { |
|
26 | - foreach($middlewares as $middleware){ |
|
27 | - if(!class_exists($middleware)) { |
|
25 | + if (null !== $middlewares) { |
|
26 | + foreach ($middlewares as $middleware) { |
|
27 | + if (!class_exists($middleware)) { |
|
28 | 28 | throw new \RuntimeException("Middleware class {$middleware} not exists"); |
29 | 29 | } |
30 | 30 | } |
@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | { |
56 | 56 | $excepts = (is_array($excepts)) ? $excepts : []; |
57 | 57 | $group = self::getInstance()->inSave()['group']; |
58 | - foreach(self::getInstance()->getRoutes() as $r => $route){ |
|
59 | - if($route['group'] !== $group || in_array($route['name'], $excepts)) { |
|
58 | + foreach (self::getInstance()->getRoutes() as $r => $route) { |
|
59 | + if ($route['group'] !== $group || in_array($route['name'], $excepts)) { |
|
60 | 60 | continue; |
61 | 61 | } |
62 | 62 | |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | |
69 | 69 | private static function existMiddleware(string $name): void |
70 | 70 | { |
71 | - if(!class_exists($name) && !array_key_exists($name, self::$globalMiddlewares)) { |
|
71 | + if (!class_exists($name) && !array_key_exists($name, self::$globalMiddlewares)) { |
|
72 | 72 | throw new \RuntimeException("Middleware {$name} does not exist"); |
73 | 73 | } |
74 | 74 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | |
82 | 82 | $this->serverRequest = (!isset($this->serverRequest)) ? $factory->createServerRequest($requestMethod, unserialize($this->current()['uri']), ['route' => $this->current()]) : $this->serverRequest; |
83 | 83 | |
84 | - foreach ($this->current()['middlewares'] as $middleware){ |
|
84 | + foreach ($this->current()['middlewares'] as $middleware) { |
|
85 | 85 | $this->currentMiddlewares[] = (class_exists($middleware)) ? new $middleware() : new $this->globalMiddlewares[$middleware](); |
86 | 86 | } |
87 | 87 | |
@@ -98,14 +98,14 @@ discard block |
||
98 | 98 | |
99 | 99 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
100 | 100 | { |
101 | - if(!$this->getInstance()->loaded()) { |
|
101 | + if (!$this->getInstance()->loaded()) { |
|
102 | 102 | $this->getInstance()->load(); |
103 | 103 | } |
104 | 104 | |
105 | 105 | $route = $this->getInstance()->current(); |
106 | - if(!empty($route)) { |
|
106 | + if (!empty($route)) { |
|
107 | 107 | |
108 | - $route['action'] = function () { |
|
108 | + $route['action'] = function() { |
|
109 | 109 | $this->getInstance()->executeBefore(); |
110 | 110 | $this->getInstance()->executeRouteAction(unserialize($this->getInstance()->current()['action'])); |
111 | 111 | $this->getInstance()->executeAfter(); |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace HnrAzevedo\Router; |
6 | 6 | |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | { |
21 | 21 | $this->hasRouteName($name); |
22 | 22 | |
23 | - if(!$this->loaded()) { |
|
23 | + if (!$this->loaded()) { |
|
24 | 24 | $this->loadIn($name); |
25 | 25 | } |
26 | 26 | |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | |
30 | 30 | public function hasCurrentRoute(): void |
31 | 31 | { |
32 | - if(!isset($this->currentRoute)) { |
|
32 | + if (!isset($this->currentRoute)) { |
|
33 | 33 | throw new \RuntimeException('Route not yet loaded'); |
34 | 34 | } |
35 | 35 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace HnrAzevedo\Router; |
6 | 6 | |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | protected function sorted(?bool $sorted = null): bool |
14 | 14 | { |
15 | - if(null !== $sorted) { |
|
15 | + if (null !== $sorted) { |
|
16 | 16 | $this->sorted = $sorted; |
17 | 17 | } |
18 | 18 | return $this->sorted; |
@@ -20,19 +20,19 @@ discard block |
||
20 | 20 | |
21 | 21 | protected function sortRoutes(): bool |
22 | 22 | { |
23 | - if($this->sorted()) { |
|
23 | + if ($this->sorted()) { |
|
24 | 24 | return true; |
25 | 25 | } |
26 | 26 | |
27 | 27 | $staticRoutes = []; |
28 | 28 | $paramRoutes = []; |
29 | 29 | |
30 | - foreach($this->getRoutes() as $r => $route){ |
|
30 | + foreach ($this->getRoutes() as $r => $route) { |
|
31 | 31 | |
32 | 32 | $path = urldecode(unserialize($route['uri'])->getPath()); |
33 | 33 | |
34 | - if(strstr($path, '{')) { |
|
35 | - $paramRoutes[$this->getKeyArray(substr_count($path, '/') + substr_count($path, '{'), $paramRoutes)] = $route; |
|
34 | + if (strstr($path, '{')) { |
|
35 | + $paramRoutes[$this->getKeyArray(substr_count($path, '/')+substr_count($path, '{'), $paramRoutes)] = $route; |
|
36 | 36 | continue; |
37 | 37 | } |
38 | 38 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | |
49 | 49 | private function getKeyArray(int $index, array $array): int |
50 | 50 | { |
51 | - while(array_key_exists($index, $array)){ |
|
51 | + while (array_key_exists($index, $array)) { |
|
52 | 52 | $index++; |
53 | 53 | } |
54 | 54 | return $index; |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | private function orderRoutes(array $routes):void |
58 | 58 | { |
59 | 59 | $kRoutes = $routes; |
60 | - foreach($routes as $r => $route){ |
|
61 | - if(array_key_exists('name', $route)) { |
|
60 | + foreach ($routes as $r => $route) { |
|
61 | + if (array_key_exists('name', $route)) { |
|
62 | 62 | unset($kRoutes[$r]); |
63 | 63 | $kRoutes["'{$route['name']}'"] = $route; |
64 | 64 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace HnrAzevedo\Router; |
6 | 6 | |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | { |
36 | 36 | $route = self::getInstance()->inSave(); |
37 | 37 | |
38 | - if(null === $value) { |
|
38 | + if (null === $value) { |
|
39 | 39 | return (isset($route['attributes'][$name])) ? $route['attributes'][$name] : null; |
40 | 40 | } |
41 | 41 | |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | public static function groupAttribute(string $name, $value = null, ?array $excepts = []): Router |
49 | 49 | { |
50 | 50 | $group = self::getInstance()->inSave()['group']; |
51 | - foreach(self::getInstance()->getRoutes() as $r => $route){ |
|
52 | - if($route['group'] !== $group || in_array($route['name'], $excepts)) { |
|
51 | + foreach (self::getInstance()->getRoutes() as $r => $route) { |
|
52 | + if ($route['group'] !== $group || in_array($route['name'], $excepts)) { |
|
53 | 53 | continue; |
54 | 54 | } |
55 | 55 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | public static function group(string $prefix, \Closure $closure): Router |
63 | 63 | { |
64 | 64 | $id = sha1(date('d/m/Y h:m:i')); |
65 | - while(array_key_exists($id, self::getInstance()->groupsName)){ |
|
65 | + while (array_key_exists($id, self::getInstance()->groupsName)) { |
|
66 | 66 | $id = sha1(date('d/m/Y h:m:i').$id); |
67 | 67 | } |
68 | 68 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | { |
84 | 84 | self::getInstance()->loaded = true; |
85 | 85 | |
86 | - if(null !== $name) { |
|
86 | + if (null !== $name) { |
|
87 | 87 | return self::getInstance()->loadByName($name); |
88 | 88 | } |
89 | 89 | |
@@ -91,15 +91,15 @@ discard block |
||
91 | 91 | |
92 | 92 | $requestMethod = (isset($_REQUEST['REQUEST_METHOD'])) ? $_REQUEST['REQUEST_METHOD'] : $_SERVER['REQUEST_METHOD']; |
93 | 93 | |
94 | - foreach(self::getInstance()->getRoutes() as $r => $route){ |
|
94 | + foreach (self::getInstance()->getRoutes() as $r => $route) { |
|
95 | 95 | self::getInstance()->currentRoute = $route; |
96 | 96 | self::getInstance()->currentRoute['name'] = $r; |
97 | 97 | |
98 | - try{ |
|
98 | + try { |
|
99 | 99 | self::getInstance()->checkMethod($route, $requestMethod); |
100 | 100 | self::getInstance()->checkData($route, (new Uri($_SERVER['REQUEST_URI']))->getPath()); |
101 | 101 | return self::getInstance(); |
102 | - }catch(\Exception $er){ |
|
102 | + }catch (\Exception $er) { |
|
103 | 103 | continue; |
104 | 104 | } |
105 | 105 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | |
114 | 114 | public static function run(?string $name = null): RouterInterface |
115 | 115 | { |
116 | - if(!self::getInstance()->loaded) { |
|
116 | + if (!self::getInstance()->loaded) { |
|
117 | 117 | self::getInstance()->load($name); |
118 | 118 | } |
119 | 119 | |
@@ -123,10 +123,10 @@ discard block |
||
123 | 123 | |
124 | 124 | self::getInstance()->executeBefore(); |
125 | 125 | |
126 | - try{ |
|
126 | + try { |
|
127 | 127 | $action = unserialize(self::getInstance()->current()['action']); |
128 | 128 | self::getInstance()->executeRouteAction((is_string($action)) ? $action : $action->getClosure()); |
129 | - }catch(\Exception $er){ |
|
129 | + }catch (\Exception $er) { |
|
130 | 130 | self::getInstance()->error = $er; |
131 | 131 | } |
132 | 132 | |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | |
140 | 140 | private function checkError(): void |
141 | 141 | { |
142 | - if(isset($this->error)) { |
|
142 | + if (isset($this->error)) { |
|
143 | 143 | throw $this->error; |
144 | 144 | } |
145 | 145 | } |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | |
154 | 154 | public static function routes(?array $routes = null): array |
155 | 155 | { |
156 | - if(null !== $routes) { |
|
156 | + if (null !== $routes) { |
|
157 | 157 | self::getInstance()->setRoutes($routes); |
158 | 158 | self::getInstance()->sortRoutes(); |
159 | 159 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | self::getInstance()->checkMethod($route, $requestMethod); |
100 | 100 | self::getInstance()->checkData($route, (new Uri($_SERVER['REQUEST_URI']))->getPath()); |
101 | 101 | return self::getInstance(); |
102 | - }catch(\Exception $er){ |
|
102 | + } catch(\Exception $er){ |
|
103 | 103 | continue; |
104 | 104 | } |
105 | 105 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | try{ |
127 | 127 | $action = unserialize(self::getInstance()->current()['action']); |
128 | 128 | self::getInstance()->executeRouteAction((is_string($action)) ? $action : $action->getClosure()); |
129 | - }catch(\Exception $er){ |
|
129 | + } catch(\Exception $er){ |
|
130 | 130 | self::getInstance()->error = $er; |
131 | 131 | } |
132 | 132 |
@@ -7,12 +7,12 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * Defines a route for the GET method |
9 | 9 | */ |
10 | -Router::get('/foo','HnrAzevedo\Router\Example\Controllers\Controller@method'); |
|
10 | +Router::get('/foo', 'HnrAzevedo\Router\Example\Controllers\Controller@method'); |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * Defines a route to the GET method with an anonymous function |
14 | 14 | */ |
15 | -Router::get('/bar', function(){ |
|
15 | +Router::get('/bar', function() { |
|
16 | 16 | // |
17 | 17 | echo '/bar executed!'; |
18 | 18 | }); |
@@ -20,14 +20,14 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * Defines a route to the POST method with an anonymous function |
22 | 22 | */ |
23 | -Router::post('/bar', function(){ |
|
23 | +Router::post('/bar', function() { |
|
24 | 24 | // |
25 | 25 | }); |
26 | 26 | |
27 | 27 | /** |
28 | 28 | * Defining route for any method |
29 | 29 | */ |
30 | -Router::any('/any', function(){ |
|
30 | +Router::any('/any', function() { |
|
31 | 31 | // |
32 | 32 | }); |
33 | 33 | |
@@ -37,14 +37,14 @@ discard block |
||
37 | 37 | * @param string $route |
38 | 38 | * @param \Closure|string $action |
39 | 39 | */ |
40 | -Router::match('GET|post', '/get_post', function(){ |
|
40 | +Router::match('GET|post', '/get_post', function() { |
|
41 | 41 | // |
42 | 42 | }); |
43 | 43 | |
44 | 44 | /** |
45 | 45 | * Defines the route name |
46 | 46 | */ |
47 | -Router::get('/named', function(){ |
|
47 | +Router::get('/named', function() { |
|
48 | 48 | // |
49 | 49 | })->name('baz'); |
50 | 50 | |
@@ -56,32 +56,32 @@ discard block |
||
56 | 56 | /** |
57 | 57 | * Run before all requests, regardless of error occurrences |
58 | 58 | */ |
59 | -Router::beforeAll(function(){ |
|
59 | +Router::beforeAll(function() { |
|
60 | 60 | // |
61 | 61 | }, null); |
62 | 62 | |
63 | 63 | /** |
64 | 64 | * Run after all requests, regardless of error occurrences |
65 | 65 | */ |
66 | -Router::afterAll(function(){ |
|
66 | +Router::afterAll(function() { |
|
67 | 67 | // |
68 | 68 | }, null); |
69 | 69 | |
70 | 70 | /** |
71 | 71 | * Executes after executing the triggered route action |
72 | 72 | */ |
73 | -Router::get('/after', function(){ |
|
73 | +Router::get('/after', function() { |
|
74 | 74 | // |
75 | -})->after(function(){ |
|
75 | +})->after(function() { |
|
76 | 76 | // |
77 | 77 | }); |
78 | 78 | |
79 | 79 | /** |
80 | 80 | * Executes before executing the triggered route action |
81 | 81 | */ |
82 | -Router::get('/before', function(){ |
|
82 | +Router::get('/before', function() { |
|
83 | 83 | // |
84 | -})->before(function(){ |
|
84 | +})->before(function() { |
|
85 | 85 | // |
86 | 86 | }); |
87 | 87 | /** |
@@ -102,21 +102,21 @@ discard block |
||
102 | 102 | /** |
103 | 103 | * Example of route definition with parameters |
104 | 104 | */ |
105 | -Router::get('/passingParameters/{param}', function($param){ |
|
105 | +Router::get('/passingParameters/{param}', function($param) { |
|
106 | 106 | echo $param; |
107 | 107 | }); |
108 | 108 | |
109 | 109 | /** |
110 | 110 | * Example of setting an optional parameter |
111 | 111 | */ |
112 | -Router::get('/passingParameters/{?optionalParam}', function($optionalParam){ |
|
112 | +Router::get('/passingParameters/{?optionalParam}', function($optionalParam) { |
|
113 | 113 | echo $optionalParam; |
114 | 114 | }); |
115 | 115 | |
116 | 116 | /** |
117 | 117 | * Example of regular expression test for parameters |
118 | 118 | */ |
119 | -Router::get('/testingParameters/{param}', function($param){ |
|
119 | +Router::get('/testingParameters/{param}', function($param) { |
|
120 | 120 | echo $param; |
121 | 121 | })->where([ |
122 | 122 | 'param'=>'[0-9]{1,11}' |
@@ -132,16 +132,16 @@ discard block |
||
132 | 132 | * @param string $prefix |
133 | 133 | * @param \Closure $routeDefinitions |
134 | 134 | */ |
135 | -Router::group('/admin', function(){ |
|
136 | - Router::get('/users/{teste}', function($teste){ |
|
135 | +Router::group('/admin', function() { |
|
136 | + Router::get('/users/{teste}', function($teste) { |
|
137 | 137 | echo $teste; |
138 | 138 | })->where([ |
139 | 139 | 'teste'=>'[a-zA-Z]*' |
140 | 140 | ]); |
141 | 141 | }); |
142 | 142 | |
143 | -Router::group('/admin2', function(){ |
|
144 | - Router::get('/users/{teste}', function($teste){ |
|
143 | +Router::group('/admin2', function() { |
|
144 | + Router::get('/users/{teste}', function($teste) { |
|
145 | 145 | echo $teste; |
146 | 146 | })->name('teste'); |
147 | 147 | }) |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | */ |
153 | 153 | ->groupWhere([ |
154 | 154 | 'teste'=>'[a-zA-Z]*' |
155 | -],[]); |
|
155 | +], []); |
|
156 | 156 | |
157 | 157 | |
158 | 158 | |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | /** |
170 | 170 | * Defining route middleware - implements Psr\Http\Server\MiddlewareInterface |
171 | 171 | */ |
172 | -Router::get('/passingParameters/{?optionalParam}', function($optionalParam = null){ |
|
172 | +Router::get('/passingParameters/{?optionalParam}', function($optionalParam = null) { |
|
173 | 173 | echo $optionalParam; |
174 | 174 | })->middleware([ |
175 | 175 | HnrAzevedo\Router\Example\Middleware\Auth::class |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | /** |
179 | 179 | * Defining middleware by nickname |
180 | 180 | */ |
181 | -Router::get('/lasted', function(){ |
|
181 | +Router::get('/lasted', function() { |
|
182 | 182 | // |
183 | 183 | })->middleware([ |
184 | 184 | 'Lasted' |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * Defining multiple middlewares |
189 | 189 | * NOTE: Importantly, the execution follows the same order of definition |
190 | 190 | */ |
191 | -Router::get('/middlewares', function(){ |
|
191 | +Router::get('/middlewares', function() { |
|
192 | 192 | // |
193 | 193 | })->middleware([ |
194 | 194 | HnrAzevedo\Router\Example\Middleware\Auth::class, |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | |
8 | 8 | use HnrAzevedo\Router\Router; |
9 | 9 | |
10 | -try{ |
|
10 | +try { |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * Add to composer.json autoload |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | */ |
36 | 36 | $action = Router::currentAction(); |
37 | 37 | |
38 | -}catch(Exception $er){ |
|
38 | +}catch (Exception $er) { |
|
39 | 39 | |
40 | 40 | die("Code Error: {$er->getCode()}".PHP_EOL."Line: {$er->getLine()}".PHP_EOL."File: {$er->getFile()}".PHP_EOL."Message: {$er->getMessage()}."); |
41 | 41 |
@@ -35,7 +35,7 @@ |
||
35 | 35 | */ |
36 | 36 | $action = Router::currentAction(); |
37 | 37 | |
38 | -}catch(Exception $er){ |
|
38 | +} catch(Exception $er){ |
|
39 | 39 | |
40 | 40 | die("Code Error: {$er->getCode()}".PHP_EOL."Line: {$er->getLine()}".PHP_EOL."File: {$er->getFile()}".PHP_EOL."Message: {$er->getMessage()}."); |
41 | 41 |
@@ -2,7 +2,7 @@ |
||
2 | 2 | |
3 | 3 | namespace HnrAzevedo\Router\Example\Controllers; |
4 | 4 | |
5 | -class Controller{ |
|
5 | +class Controller { |
|
6 | 6 | |
7 | 7 | public function method(): void |
8 | 8 | { |
@@ -45,7 +45,9 @@ discard block |
||
45 | 45 | { |
46 | 46 | try{ |
47 | 47 | foreach ($method->getAttributes() as $attr) { |
48 | - if($attr->getName() != 'HnrAzevedo\Router\Route') continue; |
|
48 | + if($attr->getName() != 'HnrAzevedo\Router\Route') { |
|
49 | + continue; |
|
50 | + } |
|
49 | 51 | |
50 | 52 | $args = $attr->getArguments(); |
51 | 53 | |
@@ -64,7 +66,7 @@ discard block |
||
64 | 66 | ->attrWhere($args) |
65 | 67 | ->attrMiddleware($args); |
66 | 68 | } |
67 | - }catch(Exception $er){ |
|
69 | + } catch(Exception $er){ |
|
68 | 70 | throw new Exception('Failed to add route via attribute: '.$er->getMessage()); |
69 | 71 | } |
70 | 72 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types = 1); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace HnrAzevedo\Router; |
6 | 6 | |
@@ -29,23 +29,23 @@ discard block |
||
29 | 29 | |
30 | 30 | public static function loadPipeline(): void |
31 | 31 | { |
32 | - foreach(self::getInstance()->getPipeline() as $line){ |
|
32 | + foreach (self::getInstance()->getPipeline() as $line) { |
|
33 | 33 | self::getInstance()->loadLine(new ReflectionObject(new $line())); |
34 | 34 | } |
35 | 35 | } |
36 | 36 | |
37 | 37 | private function loadLine(ReflectionObject $reflection): void |
38 | 38 | { |
39 | - foreach($reflection->getMethods() as $method){ |
|
39 | + foreach ($reflection->getMethods() as $method) { |
|
40 | 40 | $this->loadMethod($method); |
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | 44 | private function loadMethod(ReflectionMethod $method): void |
45 | 45 | { |
46 | - try{ |
|
46 | + try { |
|
47 | 47 | foreach ($method->getAttributes() as $attr) { |
48 | - if($attr->getName() != 'HnrAzevedo\Router\Route') continue; |
|
48 | + if ($attr->getName() != 'HnrAzevedo\Router\Route') continue; |
|
49 | 49 | |
50 | 50 | $args = $attr->getArguments(); |
51 | 51 | |
@@ -64,14 +64,14 @@ discard block |
||
64 | 64 | ->attrWhere($args) |
65 | 65 | ->attrMiddleware($args); |
66 | 66 | } |
67 | - }catch(Exception $er){ |
|
67 | + }catch (Exception $er) { |
|
68 | 68 | throw new Exception('Failed to add route via attribute: '.$er->getMessage()); |
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
72 | 72 | private function checkArgs(array $args): self |
73 | 73 | { |
74 | - if(!array_key_exists('uri', $args) && !array_key_exists(0, $args)) { |
|
74 | + if (!array_key_exists('uri', $args) && !array_key_exists(0, $args)) { |
|
75 | 75 | throw new Exception('Misconfigured route attribute'); |
76 | 76 | } |
77 | 77 | return $this; |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | |
80 | 80 | private function attrName(array $attr): self |
81 | 81 | { |
82 | - if(array_key_exists('name', $attr)) { |
|
82 | + if (array_key_exists('name', $attr)) { |
|
83 | 83 | self::getInstance()->name($attr['name']); |
84 | 84 | } |
85 | 85 | return $this; |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | |
88 | 88 | private function attrBefore(array $attr): self |
89 | 89 | { |
90 | - if(array_key_exists('before', $attr)) { |
|
90 | + if (array_key_exists('before', $attr)) { |
|
91 | 91 | self::getInstance()->before($attr['before']); |
92 | 92 | } |
93 | 93 | return $this; |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | |
96 | 96 | private function attrAfter(array $attr): self |
97 | 97 | { |
98 | - if(array_key_exists('after', $attr)) { |
|
98 | + if (array_key_exists('after', $attr)) { |
|
99 | 99 | self::getInstance()->after($attr['after']); |
100 | 100 | } |
101 | 101 | return $this; |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | |
104 | 104 | private function attrAttributes(array $attr): self |
105 | 105 | { |
106 | - if(array_key_exists('attributes', $attr)) { |
|
107 | - foreach($attr['attributes'] as $attribute => $attrValue){ |
|
106 | + if (array_key_exists('attributes', $attr)) { |
|
107 | + foreach ($attr['attributes'] as $attribute => $attrValue) { |
|
108 | 108 | self::getInstance()->attribute($attribute, $attrValue); |
109 | 109 | } |
110 | 110 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | |
114 | 114 | private function attrWhere(array $attr): self |
115 | 115 | { |
116 | - if(array_key_exists('where', $attr)) { |
|
116 | + if (array_key_exists('where', $attr)) { |
|
117 | 117 | self::getInstance()->where($attr['where']); |
118 | 118 | } |
119 | 119 | return $this; |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | |
122 | 122 | private function attrMiddleware(array $attr): self |
123 | 123 | { |
124 | - if(array_key_exists('middleware', $attr)) { |
|
124 | + if (array_key_exists('middleware', $attr)) { |
|
125 | 125 | self::getInstance()->middleware($attr['middleware']); |
126 | 126 | } |
127 | 127 | return $this; |
@@ -12,8 +12,8 @@ |
||
12 | 12 | private array $methods, |
13 | 13 | private string $name, |
14 | 14 | private ?array $where, |
15 | - private ?string|?\Closure $after, |
|
16 | - private ?string|?\Closure $before, |
|
15 | + private ?string | ?\Closure $after, |
|
16 | + private ?string | ?\Closure $before, |
|
17 | 17 | private ?array $attributes, |
18 | 18 | private ?array $middleware |
19 | 19 | ) {} |