@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | 'integer' => '\d+', |
26 | 26 | 'uuid' => '[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}', |
27 | 27 | ]; |
28 | - private const URI_FIXERS = [ |
|
28 | + private const URI_FIXERS = [ |
|
29 | 29 | '[]' => '', |
30 | 30 | '[/]' => '', |
31 | 31 | '[' => '', |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | public function __construct( |
51 | 51 | private readonly UriFactoryInterface $uriFactory, |
52 | 52 | SlugifyInterface $slugify = null |
53 | - ) { |
|
53 | + ){ |
|
54 | 54 | $this->slugify = $slugify ?? new Slugify(); |
55 | 55 | } |
56 | 56 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | |
91 | 91 | public function withBasePath(string $basePath): self |
92 | 92 | { |
93 | - if (!\str_ends_with($basePath, '/')) { |
|
93 | + if (!\str_ends_with($basePath, '/')){ |
|
94 | 94 | $basePath .= '/'; |
95 | 95 | } |
96 | 96 | |
@@ -127,12 +127,12 @@ discard block |
||
127 | 127 | */ |
128 | 128 | public function match(UriInterface $uri, array $defaults): ?array |
129 | 129 | { |
130 | - if (!$this->isCompiled()) { |
|
130 | + if (!$this->isCompiled()){ |
|
131 | 131 | $this->compile(); |
132 | 132 | } |
133 | 133 | |
134 | 134 | $matches = []; |
135 | - if (!\preg_match($this->compiled, $this->fetchTarget($uri), $matches)) { |
|
135 | + if (!\preg_match($this->compiled, $this->fetchTarget($uri), $matches)){ |
|
136 | 136 | return null; |
137 | 137 | } |
138 | 138 | |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | */ |
150 | 150 | public function uri(iterable $parameters = [], array $defaults = []): UriInterface |
151 | 151 | { |
152 | - if (!$this->isCompiled()) { |
|
152 | + if (!$this->isCompiled()){ |
|
153 | 153 | $this->compile(); |
154 | 154 | } |
155 | 155 | |
@@ -159,8 +159,8 @@ discard block |
||
159 | 159 | $this->fetchOptions($parameters, $query) |
160 | 160 | ); |
161 | 161 | |
162 | - foreach ($this->constrains as $key => $_) { |
|
163 | - if (empty($parameters[$key])) { |
|
162 | + foreach ($this->constrains as $key => $_){ |
|
163 | + if (empty($parameters[$key])){ |
|
164 | 164 | throw new UriHandlerException(\sprintf('Unable to generate Uri, parameter `%s` is missing', $key)); |
165 | 165 | } |
166 | 166 | } |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | $path = $this->interpolate($this->template, $parameters); |
170 | 170 | |
171 | 171 | //Uri with added base path and prefix |
172 | - $uri = $this->uriFactory->createUri(($this->matchHost ? '' : $this->basePath) . \trim($path, '/')); |
|
172 | + $uri = $this->uriFactory->createUri(($this->matchHost ? '' : $this->basePath).\trim($path, '/')); |
|
173 | 173 | |
174 | 174 | return empty($query) ? $uri : $uri->withQuery(\http_build_query($query)); |
175 | 175 | } |
@@ -184,18 +184,18 @@ discard block |
||
184 | 184 | $allowed = \array_keys($this->options); |
185 | 185 | |
186 | 186 | $result = []; |
187 | - foreach ($parameters as $key => $parameter) { |
|
188 | - if (\is_int($key) && isset($allowed[$key])) { |
|
187 | + foreach ($parameters as $key => $parameter){ |
|
188 | + if (\is_int($key) && isset($allowed[$key])){ |
|
189 | 189 | // this segment fetched keys from given parameters either by name or by position |
190 | 190 | $key = $allowed[$key]; |
191 | - } elseif (!\array_key_exists($key, $this->options) && \is_array($parameters)) { |
|
191 | + } elseif (!\array_key_exists($key, $this->options) && \is_array($parameters)){ |
|
192 | 192 | // all additional parameters given in array form can be glued to query string |
193 | 193 | $query[$key] = $parameter; |
194 | 194 | continue; |
195 | 195 | } |
196 | 196 | |
197 | 197 | //String must be normalized here |
198 | - if (\is_string($parameter) && !\preg_match('/^[a-z\-_0-9]+$/i', $parameter)) { |
|
198 | + if (\is_string($parameter) && !\preg_match('/^[a-z\-_0-9]+$/i', $parameter)){ |
|
199 | 199 | $result[$key] = $this->slugify->slugify($parameter); |
200 | 200 | continue; |
201 | 201 | } |
@@ -213,15 +213,15 @@ discard block |
||
213 | 213 | { |
214 | 214 | $path = $uri->getPath(); |
215 | 215 | |
216 | - if (empty($path) || $path[0] !== '/') { |
|
217 | - $path = '/' . $path; |
|
216 | + if (empty($path) || $path[0] !== '/'){ |
|
217 | + $path = '/'.$path; |
|
218 | 218 | } |
219 | 219 | |
220 | - if ($this->matchHost) { |
|
221 | - $uriString = $uri->getHost() . $path; |
|
222 | - } else { |
|
220 | + if ($this->matchHost){ |
|
221 | + $uriString = $uri->getHost().$path; |
|
222 | + }else{ |
|
223 | 223 | $uriString = \substr($path, \strlen($this->basePath)); |
224 | - if ($uriString === false) { |
|
224 | + if ($uriString === false){ |
|
225 | 225 | $uriString = ''; |
226 | 226 | } |
227 | 227 | } |
@@ -234,23 +234,23 @@ discard block |
||
234 | 234 | */ |
235 | 235 | private function compile(): void |
236 | 236 | { |
237 | - if ($this->pattern === null) { |
|
237 | + if ($this->pattern === null){ |
|
238 | 238 | throw new UriHandlerException('Unable to compile UriHandler, pattern is not set'); |
239 | 239 | } |
240 | 240 | |
241 | 241 | $options = []; |
242 | 242 | $replaces = []; |
243 | - $pattern = \rtrim(\ltrim($this->getPrefix() . '/' . $this->pattern, ':/'), '/'); |
|
243 | + $pattern = \rtrim(\ltrim($this->getPrefix().'/'.$this->pattern, ':/'), '/'); |
|
244 | 244 | |
245 | 245 | // correct [/ first occurrence] |
246 | - if (\str_starts_with($pattern, '[/')) { |
|
247 | - $pattern = '[' . \substr($pattern, 2); |
|
246 | + if (\str_starts_with($pattern, '[/')){ |
|
247 | + $pattern = '['.\substr($pattern, 2); |
|
248 | 248 | } |
249 | 249 | |
250 | - if (\preg_match_all('/<(\w+):?(.*?)?>/', $pattern, $matches)) { |
|
250 | + if (\preg_match_all('/<(\w+):?(.*?)?>/', $pattern, $matches)){ |
|
251 | 251 | $variables = \array_combine($matches[1], $matches[2]); |
252 | 252 | |
253 | - foreach ($variables as $key => $segment) { |
|
253 | + foreach ($variables as $key => $segment){ |
|
254 | 254 | $segment = $this->prepareSegment($key, $segment); |
255 | 255 | $replaces[\sprintf('<%s>', $key)] = \sprintf('(?P<%s>%s)', $key, $segment); |
256 | 256 | $options[] = $key; |
@@ -260,13 +260,13 @@ discard block |
||
260 | 260 | $template = \preg_replace('/<(\w+):?.*?>/', '<\1>', $pattern); |
261 | 261 | $options = \array_fill_keys($options, null); |
262 | 262 | |
263 | - foreach ($this->constrains as $key => $value) { |
|
264 | - if ($value instanceof Autofill) { |
|
263 | + foreach ($this->constrains as $key => $value){ |
|
264 | + if ($value instanceof Autofill){ |
|
265 | 265 | // only forces value replacement, not required to be presented as parameter |
266 | 266 | continue; |
267 | 267 | } |
268 | 268 | |
269 | - if (!\array_key_exists($key, $options) && !isset($this->defaults[$key])) { |
|
269 | + if (!\array_key_exists($key, $options) && !isset($this->defaults[$key])){ |
|
270 | 270 | throw new ConstrainException( |
271 | 271 | \sprintf( |
272 | 272 | 'Route `%s` does not define routing parameter `<%s>`.', |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | } |
278 | 278 | } |
279 | 279 | |
280 | - $this->compiled = '/^' . \strtr($template, $replaces + self::PATTERN_REPLACES) . '$/iu'; |
|
280 | + $this->compiled = '/^'.\strtr($template, $replaces + self::PATTERN_REPLACES).'$/iu'; |
|
281 | 281 | $this->template = \stripslashes(\str_replace('?', '', $template)); |
282 | 282 | $this->options = $options; |
283 | 283 | } |
@@ -288,9 +288,9 @@ discard block |
||
288 | 288 | private function interpolate(string $string, array $values): string |
289 | 289 | { |
290 | 290 | $replaces = []; |
291 | - foreach ($values as $key => $value) { |
|
291 | + foreach ($values as $key => $value){ |
|
292 | 292 | $replaces[\sprintf('<%s>', $key)] = match (true) { |
293 | - $value instanceof \Stringable || \is_scalar($value) => (string) $value, |
|
293 | + $value instanceof \Stringable || \is_scalar($value) => (string)$value, |
|
294 | 294 | default => '', |
295 | 295 | }; |
296 | 296 | } |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | private readonly ContainerInterface $container, |
50 | 50 | private readonly ?EventDispatcherInterface $eventDispatcher = null, |
51 | 51 | private readonly ?TracerInterface $tracer = new NullTracer(), |
52 | - ) { |
|
53 | - $this->basePath = '/' . \ltrim($basePath, '/'); |
|
52 | + ){ |
|
53 | + $this->basePath = '/'.\ltrim($basePath, '/'); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
@@ -64,13 +64,13 @@ discard block |
||
64 | 64 | return $this->tracer->trace( |
65 | 65 | name: 'Routing', |
66 | 66 | callback: function (SpanInterface $span) use ($request) { |
67 | - try { |
|
67 | + try{ |
|
68 | 68 | $route = $this->matchRoute($request, $routeName); |
69 | - } catch (RouteException $e) { |
|
69 | + }catch (RouteException $e){ |
|
70 | 70 | throw new RouterException('Invalid route definition', $e->getCode(), $e); |
71 | 71 | } |
72 | 72 | |
73 | - if ($route === null) { |
|
73 | + if ($route === null){ |
|
74 | 74 | $this->eventDispatcher?->dispatch(new RouteNotFound($request)); |
75 | 75 | throw new RouteNotFoundException($request->getUri()); |
76 | 76 | } |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | |
106 | 106 | public function getRoute(string $name): RouteInterface |
107 | 107 | { |
108 | - if (isset($this->routes[$name])) { |
|
108 | + if (isset($this->routes[$name])){ |
|
109 | 109 | return $this->routes[$name]; |
110 | 110 | } |
111 | 111 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | |
115 | 115 | public function getRoutes(): array |
116 | 116 | { |
117 | - if (!empty($this->default)) { |
|
117 | + if (!empty($this->default)){ |
|
118 | 118 | return $this->routes + [null => $this->default]; |
119 | 119 | } |
120 | 120 | |
@@ -123,9 +123,9 @@ discard block |
||
123 | 123 | |
124 | 124 | public function uri(string $route, iterable $parameters = []): UriInterface |
125 | 125 | { |
126 | - try { |
|
126 | + try{ |
|
127 | 127 | return $this->getRoute($route)->uri($parameters); |
128 | - } catch (UndefinedRouteException) { |
|
128 | + }catch (UndefinedRouteException){ |
|
129 | 129 | //In some cases route name can be provided as controller:action pair, we can try to |
130 | 130 | //generate such route automatically based on our default/fallback route |
131 | 131 | return $this->castRoute($route)->uri($parameters); |
@@ -137,29 +137,29 @@ discard block |
||
137 | 137 | /** @var GroupRegistry $groups */ |
138 | 138 | $groups = $this->container->get(GroupRegistry::class); |
139 | 139 | |
140 | - foreach ($routes->getCollection() as $name => $configurator) { |
|
140 | + foreach ($routes->getCollection() as $name => $configurator){ |
|
141 | 141 | $target = $configurator->target; |
142 | - if ($configurator->core !== null && $target instanceof AbstractTarget) { |
|
142 | + if ($configurator->core !== null && $target instanceof AbstractTarget){ |
|
143 | 143 | $target = $target->withCore($configurator->core); |
144 | 144 | } |
145 | 145 | |
146 | 146 | $route = new Route(\ltrim($configurator->pattern, '/'), $target, $configurator->defaults); |
147 | 147 | |
148 | - if ($configurator->middleware !== null) { |
|
148 | + if ($configurator->middleware !== null){ |
|
149 | 149 | $route = $route->withMiddleware(...$configurator->middleware); |
150 | 150 | } |
151 | 151 | |
152 | - if ($configurator->methods !== null) { |
|
152 | + if ($configurator->methods !== null){ |
|
153 | 153 | $route = $route->withVerbs(...$configurator->methods); |
154 | 154 | } |
155 | 155 | |
156 | - if (!isset($this->routes[$name]) && $name !== RoutingConfigurator::DEFAULT_ROUTE_NAME) { |
|
156 | + if (!isset($this->routes[$name]) && $name !== RoutingConfigurator::DEFAULT_ROUTE_NAME){ |
|
157 | 157 | $group = $groups->getGroup($configurator->group ?? $groups->getDefaultGroup()); |
158 | 158 | $group->setPrefix($configurator->prefix); |
159 | 159 | $group->addRoute($name, $route); |
160 | 160 | } |
161 | 161 | |
162 | - if ($name === RoutingConfigurator::DEFAULT_ROUTE_NAME) { |
|
162 | + if ($name === RoutingConfigurator::DEFAULT_ROUTE_NAME){ |
|
163 | 163 | $this->setDefault($route); |
164 | 164 | } |
165 | 165 | } |
@@ -170,17 +170,17 @@ discard block |
||
170 | 170 | */ |
171 | 171 | protected function matchRoute(ServerRequestInterface $request, string &$routeName = null): ?RouteInterface |
172 | 172 | { |
173 | - foreach ($this->routes as $name => $route) { |
|
173 | + foreach ($this->routes as $name => $route){ |
|
174 | 174 | // Matched route will return new route instance with matched parameters |
175 | 175 | $matched = $route->match($request); |
176 | 176 | |
177 | - if ($matched !== null) { |
|
177 | + if ($matched !== null){ |
|
178 | 178 | $routeName = $name; |
179 | 179 | return $matched; |
180 | 180 | } |
181 | 181 | } |
182 | 182 | |
183 | - if ($this->default !== null) { |
|
183 | + if ($this->default !== null){ |
|
184 | 184 | return $this->default->match($request); |
185 | 185 | } |
186 | 186 | |
@@ -193,14 +193,14 @@ discard block |
||
193 | 193 | */ |
194 | 194 | protected function configure(RouteInterface $route): RouteInterface |
195 | 195 | { |
196 | - if ($route instanceof ContainerizedInterface && !$route->hasContainer()) { |
|
196 | + if ($route instanceof ContainerizedInterface && !$route->hasContainer()){ |
|
197 | 197 | // isolating route in a given container |
198 | 198 | $route = $route->withContainer($this->container); |
199 | 199 | } |
200 | 200 | |
201 | - try { |
|
201 | + try{ |
|
202 | 202 | $uriHandler = $route->getUriHandler(); |
203 | - } catch (\Throwable) { |
|
203 | + }catch (\Throwable){ |
|
204 | 204 | $uriHandler = $this->uriHandler; |
205 | 205 | } |
206 | 206 | |
@@ -223,17 +223,17 @@ discard block |
||
223 | 223 | $route, |
224 | 224 | $matches |
225 | 225 | ) |
226 | - ) { |
|
226 | + ){ |
|
227 | 227 | throw new UndefinedRouteException( |
228 | 228 | "Unable to locate route or use default route with 'name/controller:action' pattern" |
229 | 229 | ); |
230 | 230 | } |
231 | 231 | |
232 | - if (!empty($matches['name'])) { |
|
232 | + if (!empty($matches['name'])){ |
|
233 | 233 | $routeObject = $this->getRoute($matches['name']); |
234 | - } elseif ($this->default !== null) { |
|
234 | + } elseif ($this->default !== null){ |
|
235 | 235 | $routeObject = $this->default; |
236 | - } else { |
|
236 | + }else{ |
|
237 | 237 | throw new UndefinedRouteException(\sprintf('Unable to locate route candidate for `%s`', $route)); |
238 | 238 | } |
239 | 239 |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | public function __construct( |
14 | 14 | private readonly RouteCollection $parent, |
15 | 15 | private readonly RouteCollection $routes |
16 | - ) { |
|
16 | + ){ |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | public function __destruct() |
@@ -23,17 +23,17 @@ discard block |
||
23 | 23 | |
24 | 24 | public function __sleep(): array |
25 | 25 | { |
26 | - throw new \BadMethodCallException('Cannot unserialize ' . self::class); |
|
26 | + throw new \BadMethodCallException('Cannot unserialize '.self::class); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | public function __wakeup() |
30 | 30 | { |
31 | - throw new \BadMethodCallException('Cannot unserialize ' . self::class); |
|
31 | + throw new \BadMethodCallException('Cannot unserialize '.self::class); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | public function defaults(array $defaults): self |
35 | 35 | { |
36 | - foreach ($this->routes->all() as $configurator) { |
|
36 | + foreach ($this->routes->all() as $configurator){ |
|
37 | 37 | $configurator->defaults($defaults); |
38 | 38 | } |
39 | 39 | |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function group(string $group): self |
47 | 47 | { |
48 | - foreach ($this->routes->all() as $configurator) { |
|
48 | + foreach ($this->routes->all() as $configurator){ |
|
49 | 49 | $configurator->group($group); |
50 | 50 | } |
51 | 51 | |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function prefix(string $prefix): self |
59 | 59 | { |
60 | - foreach ($this->routes->all() as $configurator) { |
|
60 | + foreach ($this->routes->all() as $configurator){ |
|
61 | 61 | $configurator->prefix($prefix); |
62 | 62 | } |
63 | 63 | |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function namePrefix(string $prefix): self |
71 | 71 | { |
72 | - foreach ($this->routes->all() as $name => $configurator) { |
|
73 | - $this->routes->add($prefix . $name, $configurator); |
|
72 | + foreach ($this->routes->all() as $name => $configurator){ |
|
73 | + $this->routes->add($prefix.$name, $configurator); |
|
74 | 74 | $this->routes->remove($name); |
75 | 75 | } |
76 | 76 | |
@@ -79,16 +79,16 @@ discard block |
||
79 | 79 | |
80 | 80 | public function core(CoreInterface $core): self |
81 | 81 | { |
82 | - foreach ($this->routes->all() as $configurator) { |
|
82 | + foreach ($this->routes->all() as $configurator){ |
|
83 | 83 | $configurator->core($core); |
84 | 84 | } |
85 | 85 | |
86 | 86 | return $this; |
87 | 87 | } |
88 | 88 | |
89 | - public function middleware(MiddlewareInterface|string|array $middleware): self |
|
89 | + public function middleware(MiddlewareInterface | string | array $middleware): self |
|
90 | 90 | { |
91 | - foreach ($this->routes->all() as $configurator) { |
|
91 | + foreach ($this->routes->all() as $configurator){ |
|
92 | 92 | $configurator->middleware($middleware); |
93 | 93 | } |
94 | 94 |
@@ -41,11 +41,11 @@ |
||
41 | 41 | public function __construct( |
42 | 42 | public readonly string $route, |
43 | 43 | public readonly ?string $name = null, |
44 | - public readonly array|string $methods = \Spiral\Router\Route::VERBS, |
|
44 | + public readonly array | string $methods = \Spiral\Router\Route::VERBS, |
|
45 | 45 | public readonly array $defaults = [], |
46 | 46 | public readonly ?string $group = null, |
47 | 47 | public readonly array $middleware = [], |
48 | 48 | public readonly int $priority = 0 |
49 | - ) { |
|
49 | + ){ |
|
50 | 50 | } |
51 | 51 | } |
@@ -19,15 +19,15 @@ discard block |
||
19 | 19 | public function __construct( |
20 | 20 | private readonly ReaderInterface $reader, |
21 | 21 | private readonly GroupRegistry $groups |
22 | - ) { |
|
22 | + ){ |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | public function listen(ReflectionClass $class): void |
26 | 26 | { |
27 | - foreach ($class->getMethods() as $method) { |
|
27 | + foreach ($class->getMethods() as $method){ |
|
28 | 28 | $route = $this->reader->firstFunctionMetadata($method, Route::class); |
29 | 29 | |
30 | - if ($route === null) { |
|
30 | + if ($route === null){ |
|
31 | 31 | continue; |
32 | 32 | } |
33 | 33 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | $defaultGroup = $this->groups->getDefaultGroup(); |
41 | 41 | |
42 | 42 | $routes = []; |
43 | - foreach ($this->attributes as $classes) { |
|
43 | + foreach ($this->attributes as $classes){ |
|
44 | 44 | [$method, $route] = $classes; |
45 | 45 | $class = $method->getDeclaringClass(); |
46 | 46 | |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | |
65 | 65 | private function configureRoutes(array $routes): void |
66 | 66 | { |
67 | - foreach ($routes as $name => $schema) { |
|
67 | + foreach ($routes as $name => $schema){ |
|
68 | 68 | $route = new \Spiral\Router\Route( |
69 | 69 | $schema['pattern'], |
70 | 70 | new Action($schema['controller'], $schema['action']), |
@@ -53,7 +53,7 @@ |
||
53 | 53 | $this->container = new Container(); |
54 | 54 | |
55 | 55 | $this->container->bindSingleton(UriFactoryInterface::class, new Psr17Factory()); |
56 | - $this->container->bindSingleton(RouterInterface::class, static function (UriHandler $handler, Container $container) { |
|
56 | + $this->container->bindSingleton(RouterInterface::class, static function (UriHandler $handler, Container $container){ |
|
57 | 57 | return new Router('/', $handler, $container); |
58 | 58 | }); |
59 | 59 | $this->container->bindSingleton(GroupRegistry::class, new GroupRegistry($this->container)); |
@@ -27,8 +27,8 @@ discard block |
||
27 | 27 | { |
28 | 28 | $grid = $this->table(['Name:', 'Verbs:', 'Pattern:', 'Target:', 'Group:']); |
29 | 29 | |
30 | - foreach ($router->getRoutes() as $name => $route) { |
|
31 | - if ($route instanceof Route) { |
|
30 | + foreach ($router->getRoutes() as $name => $route){ |
|
31 | + if ($route instanceof Route){ |
|
32 | 32 | $grid->addRow( |
33 | 33 | [ |
34 | 34 | $name, |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | private function getRouteGroups(GroupRegistry $registry, string $routeName): array |
53 | 53 | { |
54 | 54 | $groups = []; |
55 | - foreach ($registry as $groupName => $group) { |
|
56 | - if ($group->hasRoute($routeName)) { |
|
55 | + foreach ($registry as $groupName => $group){ |
|
56 | + if ($group->hasRoute($routeName)){ |
|
57 | 57 | $groups[] = $groupName; |
58 | 58 | } |
59 | 59 | } |
@@ -63,12 +63,12 @@ discard block |
||
63 | 63 | |
64 | 64 | private function getVerbs(Route $route): string |
65 | 65 | { |
66 | - if ($route->getVerbs() === Route::VERBS) { |
|
66 | + if ($route->getVerbs() === Route::VERBS){ |
|
67 | 67 | return '*'; |
68 | 68 | } |
69 | 69 | |
70 | 70 | $result = []; |
71 | - foreach ($route->getVerbs() as $verb) { |
|
71 | + foreach ($route->getVerbs() as $verb){ |
|
72 | 72 | $result[] = match (\strtolower($verb)) { |
73 | 73 | 'get' => '<fg=green>GET</>', |
74 | 74 | 'post' => '<fg=blue>POST</>', |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | return \preg_replace_callback( |
94 | 94 | '/<([^>]*)>/', |
95 | 95 | static fn ($m) => \sprintf('<fg=magenta>%s</>', $m[0]), |
96 | - !empty($prefix) ? $prefix . '/' . \trim($pattern, '/') : $pattern |
|
96 | + !empty($prefix) ? $prefix.'/'.\trim($pattern, '/') : $pattern |
|
97 | 97 | ); |
98 | 98 | } |
99 | 99 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | private function getTarget(Route $route, KernelInterface $kernel): string |
105 | 105 | { |
106 | 106 | $target = $this->getValue($route, 'target'); |
107 | - switch (true) { |
|
107 | + switch (true){ |
|
108 | 108 | case $target instanceof \Closure: |
109 | 109 | $reflection = new \ReflectionFunction($target); |
110 | 110 | |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | |
130 | 130 | case $target instanceof Group: |
131 | 131 | $result = []; |
132 | - foreach ($this->getValue($target, 'controllers') as $alias => $class) { |
|
132 | + foreach ($this->getValue($target, 'controllers') as $alias => $class){ |
|
133 | 133 | $result[] = \sprintf('%s => %s', $alias, $this->relativeClass($class, $kernel)); |
134 | 134 | } |
135 | 135 | |
@@ -148,10 +148,10 @@ discard block |
||
148 | 148 | |
149 | 149 | private function getValue(object $object, string $property): mixed |
150 | 150 | { |
151 | - try { |
|
151 | + try{ |
|
152 | 152 | $r = new \ReflectionObject($object); |
153 | 153 | $prop = $r->getProperty($property); |
154 | - } catch (\Throwable $e) { |
|
154 | + }catch (\Throwable $e){ |
|
155 | 155 | return $e->getMessage(); |
156 | 156 | } |
157 | 157 | |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | { |
163 | 163 | $r = new \ReflectionObject($kernel); |
164 | 164 | |
165 | - if (\str_starts_with($class, $r->getNamespaceName())) { |
|
165 | + if (\str_starts_with($class, $r->getNamespaceName())){ |
|
166 | 166 | return \substr($class, \strlen($r->getNamespaceName()) + 1); |
167 | 167 | } |
168 | 168 |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | private readonly RouterInterface $router, |
34 | 34 | private readonly UriHandler $handler, |
35 | 35 | private readonly ?string $name = null |
36 | - ) { |
|
36 | + ){ |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -70,9 +70,9 @@ discard block |
||
70 | 70 | return $this; |
71 | 71 | } |
72 | 72 | |
73 | - public function setCore(Autowire|CoreInterface|string $core): self |
|
73 | + public function setCore(Autowire | CoreInterface | string $core): self |
|
74 | 74 | { |
75 | - if (!$core instanceof CoreInterface) { |
|
75 | + if (!$core instanceof CoreInterface){ |
|
76 | 76 | $core = $this->container->get($core); |
77 | 77 | } |
78 | 78 | $this->core = $core; |
@@ -86,13 +86,13 @@ discard block |
||
86 | 86 | /** |
87 | 87 | * @param MiddlewareInterface|Autowire|class-string<MiddlewareInterface>|non-empty-string $middleware |
88 | 88 | */ |
89 | - public function addMiddleware(MiddlewareInterface|Autowire|string $middleware): self |
|
89 | + public function addMiddleware(MiddlewareInterface | Autowire | string $middleware): self |
|
90 | 90 | { |
91 | 91 | $this->middleware[] = $middleware; |
92 | 92 | |
93 | - if ($this->container instanceof BinderInterface && $this->name !== null) { |
|
93 | + if ($this->container instanceof BinderInterface && $this->name !== null){ |
|
94 | 94 | $this->container->bind( |
95 | - 'middleware:' . $this->name, |
|
95 | + 'middleware:'.$this->name, |
|
96 | 96 | function (PipelineFactory $factory): Pipeline { |
97 | 97 | return $factory->createWithMiddleware($this->middleware); |
98 | 98 | } |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public function flushRoutes(): void |
114 | 114 | { |
115 | - foreach ($this->routes as $name) { |
|
115 | + foreach ($this->routes as $name){ |
|
116 | 116 | $this->router->setRoute($name, $this->applyGroupParams($this->router->getRoute($name))); |
117 | 117 | } |
118 | 118 | } |
@@ -122,30 +122,30 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public function addRoute(string $name, Route $route): self |
124 | 124 | { |
125 | - if ($this->name !== null && $this->middleware !== []) { |
|
126 | - $route = $route->withMiddleware('middleware:' . $this->name); |
|
125 | + if ($this->name !== null && $this->middleware !== []){ |
|
126 | + $route = $route->withMiddleware('middleware:'.$this->name); |
|
127 | 127 | } |
128 | 128 | |
129 | - $this->routes[] = $this->namePrefix . $name; |
|
129 | + $this->routes[] = $this->namePrefix.$name; |
|
130 | 130 | |
131 | - $this->router->setRoute($this->namePrefix . $name, $this->applyGroupParams($route)); |
|
131 | + $this->router->setRoute($this->namePrefix.$name, $this->applyGroupParams($route)); |
|
132 | 132 | |
133 | 133 | return $this; |
134 | 134 | } |
135 | 135 | |
136 | 136 | private function applyGroupParams(Route $route): Route |
137 | 137 | { |
138 | - if ($this->core !== null) { |
|
138 | + if ($this->core !== null){ |
|
139 | 139 | $target = $route->getTarget(); |
140 | 140 | |
141 | - if ($target instanceof AbstractTarget) { |
|
141 | + if ($target instanceof AbstractTarget){ |
|
142 | 142 | $route = $route->withTarget($target->withCore($this->core)); |
143 | 143 | } |
144 | 144 | } |
145 | 145 | |
146 | - try { |
|
146 | + try{ |
|
147 | 147 | $uriHandler = $route->getUriHandler(); |
148 | - } catch (\Throwable) { |
|
148 | + }catch (\Throwable){ |
|
149 | 149 | $uriHandler = $this->handler; |
150 | 150 | } |
151 | 151 |
@@ -18,12 +18,12 @@ |
||
18 | 18 | |
19 | 19 | public function __construct( |
20 | 20 | private readonly FactoryInterface $factory |
21 | - ) { |
|
21 | + ){ |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | public function getGroup(string $name): RouteGroup |
25 | 25 | { |
26 | - if (!isset($this->groups[$name])) { |
|
26 | + if (!isset($this->groups[$name])){ |
|
27 | 27 | $this->groups[$name] = $this->factory->make(RouteGroup::class, ['name' => $name]); |
28 | 28 | } |
29 | 29 |