@@ -21,7 +21,7 @@ |
||
21 | 21 | ?string $clientFilename = null, |
22 | 22 | ?string $clientMediaType = null |
23 | 23 | ): UploadedFileInterface { |
24 | - if ($size === null) { |
|
24 | + if ($size === null){ |
|
25 | 25 | $size = $stream->getSize(); |
26 | 26 | } |
27 | 27 |
@@ -21,7 +21,8 @@ |
||
21 | 21 | ?string $clientFilename = null, |
22 | 22 | ?string $clientMediaType = null |
23 | 23 | ): UploadedFileInterface { |
24 | - if ($size === null) { |
|
24 | + if ($size === null) |
|
25 | + { |
|
25 | 26 | $size = $stream->getSize(); |
26 | 27 | } |
27 | 28 |
@@ -14,6 +14,6 @@ |
||
14 | 14 | |
15 | 15 | public function callAction(string $controller, ?string $action = null, array $parameters = []): string |
16 | 16 | { |
17 | - return '@wrapped.' . $this->core->callAction($controller, $action, $parameters); |
|
17 | + return '@wrapped.'.$this->core->callAction($controller, $action, $parameters); |
|
18 | 18 | } |
19 | 19 | } |
@@ -12,8 +12,8 @@ |
||
12 | 12 | private readonly UriInterface $uri, |
13 | 13 | int $code = 0, |
14 | 14 | ?\Throwable $previous = null |
15 | - ) { |
|
16 | - parent::__construct(\sprintf('Unable to route `%s`.', (string) $uri), $code, $previous); |
|
15 | + ){ |
|
16 | + parent::__construct(\sprintf('Unable to route `%s`.', (string)$uri), $code, $previous); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | public function getUri(): UriInterface |
@@ -52,9 +52,9 @@ discard block |
||
52 | 52 | private readonly ContainerInterface $container, |
53 | 53 | private readonly ?EventDispatcherInterface $eventDispatcher = null, |
54 | 54 | ?TracerInterface $tracer = null, |
55 | - ) { |
|
55 | + ){ |
|
56 | 56 | $this->tracer = $tracer ?? new NullTracer(); |
57 | - $this->basePath = '/' . \ltrim($basePath, '/'); |
|
57 | + $this->basePath = '/'.\ltrim($basePath, '/'); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -68,13 +68,13 @@ discard block |
||
68 | 68 | return $this->tracer->trace( |
69 | 69 | name: 'Routing', |
70 | 70 | callback: function (SpanInterface $span) use ($request) { |
71 | - try { |
|
71 | + try{ |
|
72 | 72 | $route = $this->matchRoute($request, $routeName); |
73 | - } catch (RouteException $e) { |
|
73 | + }catch (RouteException $e){ |
|
74 | 74 | throw new RouterException('Invalid route definition', $e->getCode(), $e); |
75 | 75 | } |
76 | 76 | |
77 | - if ($route === null) { |
|
77 | + if ($route === null){ |
|
78 | 78 | $this->eventDispatcher?->dispatch(new RouteNotFound($request)); |
79 | 79 | throw new RouteNotFoundException($request->getUri()); |
80 | 80 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | |
110 | 110 | public function getRoute(string $name): RouteInterface |
111 | 111 | { |
112 | - if (isset($this->routes[$name])) { |
|
112 | + if (isset($this->routes[$name])){ |
|
113 | 113 | return $this->routes[$name]; |
114 | 114 | } |
115 | 115 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | |
119 | 119 | public function getRoutes(): array |
120 | 120 | { |
121 | - if (!empty($this->default)) { |
|
121 | + if (!empty($this->default)){ |
|
122 | 122 | return $this->routes + [null => $this->default]; |
123 | 123 | } |
124 | 124 | |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | |
128 | 128 | public function uri(string $route, iterable $parameters = []): UriInterface |
129 | 129 | { |
130 | - try { |
|
130 | + try{ |
|
131 | 131 | return $this->getRoute($route)->uri($parameters); |
132 | - } catch (UndefinedRouteException) { |
|
132 | + }catch (UndefinedRouteException){ |
|
133 | 133 | //In some cases route name can be provided as controller:action pair, we can try to |
134 | 134 | //generate such route automatically based on our default/fallback route |
135 | 135 | return $this->castRoute($route)->uri($parameters); |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | /** @var GroupRegistry $groups */ |
142 | 142 | $groups = $this->container->get(GroupRegistry::class); |
143 | 143 | |
144 | - foreach ($routes->getCollection() as $name => $configurator) { |
|
144 | + foreach ($routes->getCollection() as $name => $configurator){ |
|
145 | 145 | $target = $configurator->target; |
146 | - if ($configurator->core !== null && $target instanceof AbstractTarget) { |
|
146 | + if ($configurator->core !== null && $target instanceof AbstractTarget){ |
|
147 | 147 | $target = $target->withCore($configurator->core); |
148 | 148 | } |
149 | 149 | |
@@ -152,21 +152,21 @@ discard block |
||
152 | 152 | : \ltrim($configurator->pattern, '/'); |
153 | 153 | $route = new Route($pattern, $target, $configurator->defaults); |
154 | 154 | |
155 | - if ($configurator->middleware !== null) { |
|
155 | + if ($configurator->middleware !== null){ |
|
156 | 156 | $route = $route->withMiddleware(...$configurator->middleware); |
157 | 157 | } |
158 | 158 | |
159 | - if ($configurator->methods !== null) { |
|
159 | + if ($configurator->methods !== null){ |
|
160 | 160 | $route = $route->withVerbs(...$configurator->methods); |
161 | 161 | } |
162 | 162 | |
163 | - if (!isset($this->routes[$name]) && $name !== RoutingConfigurator::DEFAULT_ROUTE_NAME) { |
|
163 | + if (!isset($this->routes[$name]) && $name !== RoutingConfigurator::DEFAULT_ROUTE_NAME){ |
|
164 | 164 | $group = $groups->getGroup($configurator->group ?? $groups->getDefaultGroup()); |
165 | 165 | $group->setPrefix($configurator->prefix); |
166 | 166 | $group->addRoute($name, $route); |
167 | 167 | } |
168 | 168 | |
169 | - if ($name === RoutingConfigurator::DEFAULT_ROUTE_NAME) { |
|
169 | + if ($name === RoutingConfigurator::DEFAULT_ROUTE_NAME){ |
|
170 | 170 | $this->setDefault($route); |
171 | 171 | } |
172 | 172 | } |
@@ -177,17 +177,17 @@ discard block |
||
177 | 177 | */ |
178 | 178 | protected function matchRoute(ServerRequestInterface $request, ?string &$routeName = null): ?RouteInterface |
179 | 179 | { |
180 | - foreach ($this->routes as $name => $route) { |
|
180 | + foreach ($this->routes as $name => $route){ |
|
181 | 181 | // Matched route will return new route instance with matched parameters |
182 | 182 | $matched = $route->match($request); |
183 | 183 | |
184 | - if ($matched !== null) { |
|
184 | + if ($matched !== null){ |
|
185 | 185 | $routeName = $name; |
186 | 186 | return $matched; |
187 | 187 | } |
188 | 188 | } |
189 | 189 | |
190 | - if ($this->default !== null) { |
|
190 | + if ($this->default !== null){ |
|
191 | 191 | return $this->default->match($request); |
192 | 192 | } |
193 | 193 | |
@@ -200,14 +200,14 @@ discard block |
||
200 | 200 | */ |
201 | 201 | protected function configure(RouteInterface $route): RouteInterface |
202 | 202 | { |
203 | - if ($route instanceof ContainerizedInterface && !$route->hasContainer()) { |
|
203 | + if ($route instanceof ContainerizedInterface && !$route->hasContainer()){ |
|
204 | 204 | // isolating route in a given container |
205 | 205 | $route = $route->withContainer($this->container); |
206 | 206 | } |
207 | 207 | |
208 | - try { |
|
208 | + try{ |
|
209 | 209 | $uriHandler = $route->getUriHandler(); |
210 | - } catch (\Throwable) { |
|
210 | + }catch (\Throwable){ |
|
211 | 211 | $uriHandler = $this->uriHandler; |
212 | 212 | } |
213 | 213 | |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | $route, |
231 | 231 | $matches |
232 | 232 | ) |
233 | - ) { |
|
233 | + ){ |
|
234 | 234 | throw new UndefinedRouteException( |
235 | 235 | "Unable to locate route or use default route with 'name/controller:action' pattern" |
236 | 236 | ); |
@@ -239,11 +239,11 @@ discard block |
||
239 | 239 | /** |
240 | 240 | * @var Matches $matches |
241 | 241 | */ |
242 | - if (!empty($matches['name'])) { |
|
242 | + if (!empty($matches['name'])){ |
|
243 | 243 | $routeObject = $this->getRoute($matches['name']); |
244 | - } elseif ($this->default !== null) { |
|
244 | + } elseif ($this->default !== null){ |
|
245 | 245 | $routeObject = $this->default; |
246 | - } else { |
|
246 | + }else{ |
|
247 | 247 | throw new UndefinedRouteException(\sprintf('Unable to locate route candidate for `%s`', $route)); |
248 | 248 | } |
249 | 249 |
@@ -67,14 +67,19 @@ discard block |
||
67 | 67 | |
68 | 68 | return $this->tracer->trace( |
69 | 69 | name: 'Routing', |
70 | - callback: function (SpanInterface $span) use ($request) { |
|
71 | - try { |
|
70 | + callback: function (SpanInterface $span) use ($request) |
|
71 | + { |
|
72 | + try |
|
73 | + { |
|
72 | 74 | $route = $this->matchRoute($request, $routeName); |
73 | - } catch (RouteException $e) { |
|
75 | + } |
|
76 | + catch (RouteException $e) |
|
77 | + { |
|
74 | 78 | throw new RouterException('Invalid route definition', $e->getCode(), $e); |
75 | 79 | } |
76 | 80 | |
77 | - if ($route === null) { |
|
81 | + if ($route === null) |
|
82 | + { |
|
78 | 83 | $this->eventDispatcher?->dispatch(new RouteNotFound($request)); |
79 | 84 | throw new RouteNotFoundException($request->getUri()); |
80 | 85 | } |
@@ -109,7 +114,8 @@ discard block |
||
109 | 114 | |
110 | 115 | public function getRoute(string $name): RouteInterface |
111 | 116 | { |
112 | - if (isset($this->routes[$name])) { |
|
117 | + if (isset($this->routes[$name])) |
|
118 | + { |
|
113 | 119 | return $this->routes[$name]; |
114 | 120 | } |
115 | 121 | |
@@ -118,7 +124,8 @@ discard block |
||
118 | 124 | |
119 | 125 | public function getRoutes(): array |
120 | 126 | { |
121 | - if (!empty($this->default)) { |
|
127 | + if (!empty($this->default)) |
|
128 | + { |
|
122 | 129 | return $this->routes + [null => $this->default]; |
123 | 130 | } |
124 | 131 | |
@@ -127,9 +134,12 @@ discard block |
||
127 | 134 | |
128 | 135 | public function uri(string $route, iterable $parameters = []): UriInterface |
129 | 136 | { |
130 | - try { |
|
137 | + try |
|
138 | + { |
|
131 | 139 | return $this->getRoute($route)->uri($parameters); |
132 | - } catch (UndefinedRouteException) { |
|
140 | + } |
|
141 | + catch (UndefinedRouteException) |
|
142 | + { |
|
133 | 143 | //In some cases route name can be provided as controller:action pair, we can try to |
134 | 144 | //generate such route automatically based on our default/fallback route |
135 | 145 | return $this->castRoute($route)->uri($parameters); |
@@ -141,9 +151,11 @@ discard block |
||
141 | 151 | /** @var GroupRegistry $groups */ |
142 | 152 | $groups = $this->container->get(GroupRegistry::class); |
143 | 153 | |
144 | - foreach ($routes->getCollection() as $name => $configurator) { |
|
154 | + foreach ($routes->getCollection() as $name => $configurator) |
|
155 | + { |
|
145 | 156 | $target = $configurator->target; |
146 | - if ($configurator->core !== null && $target instanceof AbstractTarget) { |
|
157 | + if ($configurator->core !== null && $target instanceof AbstractTarget) |
|
158 | + { |
|
147 | 159 | $target = $target->withCore($configurator->core); |
148 | 160 | } |
149 | 161 | |
@@ -152,21 +164,25 @@ discard block |
||
152 | 164 | : \ltrim($configurator->pattern, '/'); |
153 | 165 | $route = new Route($pattern, $target, $configurator->defaults); |
154 | 166 | |
155 | - if ($configurator->middleware !== null) { |
|
167 | + if ($configurator->middleware !== null) |
|
168 | + { |
|
156 | 169 | $route = $route->withMiddleware(...$configurator->middleware); |
157 | 170 | } |
158 | 171 | |
159 | - if ($configurator->methods !== null) { |
|
172 | + if ($configurator->methods !== null) |
|
173 | + { |
|
160 | 174 | $route = $route->withVerbs(...$configurator->methods); |
161 | 175 | } |
162 | 176 | |
163 | - if (!isset($this->routes[$name]) && $name !== RoutingConfigurator::DEFAULT_ROUTE_NAME) { |
|
177 | + if (!isset($this->routes[$name]) && $name !== RoutingConfigurator::DEFAULT_ROUTE_NAME) |
|
178 | + { |
|
164 | 179 | $group = $groups->getGroup($configurator->group ?? $groups->getDefaultGroup()); |
165 | 180 | $group->setPrefix($configurator->prefix); |
166 | 181 | $group->addRoute($name, $route); |
167 | 182 | } |
168 | 183 | |
169 | - if ($name === RoutingConfigurator::DEFAULT_ROUTE_NAME) { |
|
184 | + if ($name === RoutingConfigurator::DEFAULT_ROUTE_NAME) |
|
185 | + { |
|
170 | 186 | $this->setDefault($route); |
171 | 187 | } |
172 | 188 | } |
@@ -177,17 +193,20 @@ discard block |
||
177 | 193 | */ |
178 | 194 | protected function matchRoute(ServerRequestInterface $request, ?string &$routeName = null): ?RouteInterface |
179 | 195 | { |
180 | - foreach ($this->routes as $name => $route) { |
|
196 | + foreach ($this->routes as $name => $route) |
|
197 | + { |
|
181 | 198 | // Matched route will return new route instance with matched parameters |
182 | 199 | $matched = $route->match($request); |
183 | 200 | |
184 | - if ($matched !== null) { |
|
201 | + if ($matched !== null) |
|
202 | + { |
|
185 | 203 | $routeName = $name; |
186 | 204 | return $matched; |
187 | 205 | } |
188 | 206 | } |
189 | 207 | |
190 | - if ($this->default !== null) { |
|
208 | + if ($this->default !== null) |
|
209 | + { |
|
191 | 210 | return $this->default->match($request); |
192 | 211 | } |
193 | 212 | |
@@ -200,14 +219,18 @@ discard block |
||
200 | 219 | */ |
201 | 220 | protected function configure(RouteInterface $route): RouteInterface |
202 | 221 | { |
203 | - if ($route instanceof ContainerizedInterface && !$route->hasContainer()) { |
|
222 | + if ($route instanceof ContainerizedInterface && !$route->hasContainer()) |
|
223 | + { |
|
204 | 224 | // isolating route in a given container |
205 | 225 | $route = $route->withContainer($this->container); |
206 | 226 | } |
207 | 227 | |
208 | - try { |
|
228 | + try |
|
229 | + { |
|
209 | 230 | $uriHandler = $route->getUriHandler(); |
210 | - } catch (\Throwable) { |
|
231 | + } |
|
232 | + catch (\Throwable) |
|
233 | + { |
|
211 | 234 | $uriHandler = $this->uriHandler; |
212 | 235 | } |
213 | 236 | |
@@ -239,11 +262,16 @@ discard block |
||
239 | 262 | /** |
240 | 263 | * @var Matches $matches |
241 | 264 | */ |
242 | - if (!empty($matches['name'])) { |
|
265 | + if (!empty($matches['name'])) |
|
266 | + { |
|
243 | 267 | $routeObject = $this->getRoute($matches['name']); |
244 | - } elseif ($this->default !== null) { |
|
268 | + } |
|
269 | + elseif ($this->default !== null) |
|
270 | + { |
|
245 | 271 | $routeObject = $this->default; |
246 | - } else { |
|
272 | + } |
|
273 | + else |
|
274 | + { |
|
247 | 275 | throw new UndefinedRouteException(\sprintf('Unable to locate route candidate for `%s`', $route)); |
248 | 276 | } |
249 | 277 |
@@ -16,15 +16,15 @@ |
||
16 | 16 | */ |
17 | 17 | public function __construct(array $loaders = []) |
18 | 18 | { |
19 | - foreach ($loaders as $loader) { |
|
19 | + foreach ($loaders as $loader){ |
|
20 | 20 | $this->addLoader($loader); |
21 | 21 | } |
22 | 22 | } |
23 | 23 | |
24 | - public function resolve(mixed $resource, ?string $type = null): LoaderInterface|false |
|
24 | + public function resolve(mixed $resource, ?string $type = null): LoaderInterface | false |
|
25 | 25 | { |
26 | - foreach ($this->loaders as $loader) { |
|
27 | - if ($loader->supports($resource, $type)) { |
|
26 | + foreach ($this->loaders as $loader){ |
|
27 | + if ($loader->supports($resource, $type)){ |
|
28 | 28 | return $loader; |
29 | 29 | } |
30 | 30 | } |
@@ -16,15 +16,18 @@ |
||
16 | 16 | */ |
17 | 17 | public function __construct(array $loaders = []) |
18 | 18 | { |
19 | - foreach ($loaders as $loader) { |
|
19 | + foreach ($loaders as $loader) |
|
20 | + { |
|
20 | 21 | $this->addLoader($loader); |
21 | 22 | } |
22 | 23 | } |
23 | 24 | |
24 | 25 | public function resolve(mixed $resource, ?string $type = null): LoaderInterface|false |
25 | 26 | { |
26 | - foreach ($this->loaders as $loader) { |
|
27 | - if ($loader->supports($resource, $type)) { |
|
27 | + foreach ($this->loaders as $loader) |
|
28 | + { |
|
29 | + if ($loader->supports($resource, $type)) |
|
30 | + { |
|
28 | 31 | return $loader; |
29 | 32 | } |
30 | 33 | } |
@@ -10,12 +10,12 @@ |
||
10 | 10 | { |
11 | 11 | public function __construct( |
12 | 12 | private readonly LoaderRegistryInterface $registry |
13 | - ) { |
|
13 | + ){ |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | public function load(mixed $resource, ?string $type = null): mixed |
17 | 17 | { |
18 | - if (false === $loader = $this->registry->resolve($resource, $type)) { |
|
18 | + if (false === $loader = $this->registry->resolve($resource, $type)){ |
|
19 | 19 | throw new LoaderLoadException(\sprintf('Loader for type [%s] not found.', $type ?? '')); |
20 | 20 | } |
21 | 21 |
@@ -15,7 +15,8 @@ |
||
15 | 15 | |
16 | 16 | public function load(mixed $resource, ?string $type = null): mixed |
17 | 17 | { |
18 | - if (false === $loader = $this->registry->resolve($resource, $type)) { |
|
18 | + if (false === $loader = $this->registry->resolve($resource, $type)) |
|
19 | + { |
|
19 | 20 | throw new LoaderLoadException(\sprintf('Loader for type [%s] not found.', $type ?? '')); |
20 | 21 | } |
21 | 22 |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | public function __construct( |
17 | 17 | private readonly FactoryInterface $factory, |
18 | 18 | private readonly ResolverInterface $resolver, |
19 | - ) { |
|
19 | + ){ |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function load(mixed $resource, ?string $type = null): RouteCollection |
26 | 26 | { |
27 | - if (!\file_exists($resource)) { |
|
27 | + if (!\file_exists($resource)){ |
|
28 | 28 | throw new LoaderLoadException(\sprintf('File [%s] does not exist.', $resource)); |
29 | 29 | } |
30 | 30 |
@@ -24,7 +24,8 @@ |
||
24 | 24 | */ |
25 | 25 | public function load(mixed $resource, ?string $type = null): RouteCollection |
26 | 26 | { |
27 | - if (!\file_exists($resource)) { |
|
27 | + if (!\file_exists($resource)) |
|
28 | + { |
|
28 | 29 | throw new LoaderLoadException(\sprintf('File [%s] does not exist.', $resource)); |
29 | 30 | } |
30 | 31 |
@@ -14,19 +14,19 @@ |
||
14 | 14 | public function __construct( |
15 | 15 | private readonly RouteCollection $collection, |
16 | 16 | private readonly LoaderInterface $loader |
17 | - ) { |
|
17 | + ){ |
|
18 | 18 | } |
19 | 19 | |
20 | - public function import(string|array $resource, ?string $type = null): ImportConfigurator |
|
20 | + public function import(string | array $resource, ?string $type = null): ImportConfigurator |
|
21 | 21 | { |
22 | 22 | $imported = $this->loader->load($resource, $type) ?: []; |
23 | 23 | |
24 | - if (!\is_array($imported)) { |
|
24 | + if (!\is_array($imported)){ |
|
25 | 25 | return new ImportConfigurator($this->collection, $imported); |
26 | 26 | } |
27 | 27 | |
28 | 28 | $mergedCollection = new RouteCollection(); |
29 | - foreach ($imported as $subCollection) { |
|
29 | + foreach ($imported as $subCollection){ |
|
30 | 30 | $mergedCollection->addCollection($subCollection); |
31 | 31 | } |
32 | 32 |
@@ -11,5 +11,5 @@ |
||
11 | 11 | * |
12 | 12 | * @param string|null $type The resource type or null if unknown |
13 | 13 | */ |
14 | - public function resolve(mixed $resource, ?string $type = null): LoaderInterface|false; |
|
14 | + public function resolve(mixed $resource, ?string $type = null): LoaderInterface | false; |
|
15 | 15 | } |