@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | public function __construct( |
| 21 | 21 | protected string $pattern, |
| 22 | 22 | array $defaults = [] |
| 23 | - ) { |
|
| 23 | + ){ |
|
| 24 | 24 | $this->defaults = $defaults; |
| 25 | 25 | } |
| 26 | 26 | |
@@ -39,12 +39,12 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | public function match(Request $request): ?static |
| 41 | 41 | { |
| 42 | - if (!\in_array(\strtoupper($request->getMethod()), $this->getVerbs(), true)) { |
|
| 42 | + if (!\in_array(\strtoupper($request->getMethod()), $this->getVerbs(), true)){ |
|
| 43 | 43 | return null; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | $matches = $this->uriHandler->match($request->getUri(), $this->defaults); |
| 47 | - if ($matches === null) { |
|
| 47 | + if ($matches === null){ |
|
| 48 | 48 | return null; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -39,12 +39,14 @@ |
||
| 39 | 39 | |
| 40 | 40 | public function match(Request $request): ?static |
| 41 | 41 | { |
| 42 | - if (!\in_array(\strtoupper($request->getMethod()), $this->getVerbs(), true)) { |
|
| 42 | + if (!\in_array(\strtoupper($request->getMethod()), $this->getVerbs(), true)) |
|
| 43 | + { |
|
| 43 | 44 | return null; |
| 44 | 45 | } |
| 45 | 46 | |
| 46 | 47 | $matches = $this->uriHandler->match($request->getUri(), $this->defaults); |
| 47 | - if ($matches === null) { |
|
| 48 | + if ($matches === null) |
|
| 49 | + { |
|
| 48 | 50 | return null; |
| 49 | 51 | } |
| 50 | 52 | |
@@ -45,8 +45,8 @@ discard block |
||
| 45 | 45 | private readonly UriHandler $uriHandler, |
| 46 | 46 | private readonly ContainerInterface $container, |
| 47 | 47 | private readonly ?EventDispatcherInterface $eventDispatcher = null |
| 48 | - ) { |
|
| 49 | - $this->basePath = '/' . \ltrim($basePath, '/'); |
|
| 48 | + ){ |
|
| 49 | + $this->basePath = '/'.\ltrim($basePath, '/'); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
@@ -57,13 +57,13 @@ discard block |
||
| 57 | 57 | { |
| 58 | 58 | $this->eventDispatcher?->dispatch(new Routing($request)); |
| 59 | 59 | |
| 60 | - try { |
|
| 60 | + try{ |
|
| 61 | 61 | $route = $this->matchRoute($request, $routeName); |
| 62 | - } catch (RouteException $e) { |
|
| 62 | + }catch (RouteException $e){ |
|
| 63 | 63 | throw new RouterException('Invalid route definition', $e->getCode(), $e); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - if ($route === null) { |
|
| 66 | + if ($route === null){ |
|
| 67 | 67 | $this->eventDispatcher?->dispatch(new RouteNotFound($request)); |
| 68 | 68 | throw new RouteNotFoundException($request->getUri()); |
| 69 | 69 | } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | public function getRoute(string $name): RouteInterface |
| 93 | 93 | { |
| 94 | - if (isset($this->routes[$name])) { |
|
| 94 | + if (isset($this->routes[$name])){ |
|
| 95 | 95 | return $this->routes[$name]; |
| 96 | 96 | } |
| 97 | 97 | |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | |
| 101 | 101 | public function getRoutes(): array |
| 102 | 102 | { |
| 103 | - if (!empty($this->default)) { |
|
| 103 | + if (!empty($this->default)){ |
|
| 104 | 104 | return $this->routes + [null => $this->default]; |
| 105 | 105 | } |
| 106 | 106 | |
@@ -109,9 +109,9 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | public function uri(string $route, iterable $parameters = []): UriInterface |
| 111 | 111 | { |
| 112 | - try { |
|
| 112 | + try{ |
|
| 113 | 113 | return $this->getRoute($route)->uri($parameters); |
| 114 | - } catch (UndefinedRouteException) { |
|
| 114 | + }catch (UndefinedRouteException){ |
|
| 115 | 115 | //In some cases route name can be provided as controller:action pair, we can try to |
| 116 | 116 | //generate such route automatically based on our default/fallback route |
| 117 | 117 | return $this->castRoute($route)->uri($parameters); |
@@ -123,31 +123,31 @@ discard block |
||
| 123 | 123 | /** @var GroupRegistry $groups */ |
| 124 | 124 | $groups = $this->container->get(GroupRegistry::class); |
| 125 | 125 | |
| 126 | - foreach ($routes->getCollection() as $name => $configurator) { |
|
| 126 | + foreach ($routes->getCollection() as $name => $configurator){ |
|
| 127 | 127 | $target = $configurator->target; |
| 128 | - if ($configurator->core !== null && $target instanceof AbstractTarget) { |
|
| 128 | + if ($configurator->core !== null && $target instanceof AbstractTarget){ |
|
| 129 | 129 | $target = $target->withCore($configurator->core); |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | $route = new Route( |
| 133 | - $configurator->prefix . '/' . \ltrim($configurator->pattern, '/'), |
|
| 133 | + $configurator->prefix.'/'.\ltrim($configurator->pattern, '/'), |
|
| 134 | 134 | $target, |
| 135 | 135 | $configurator->defaults |
| 136 | 136 | ); |
| 137 | 137 | |
| 138 | - if ($configurator->middleware !== null) { |
|
| 138 | + if ($configurator->middleware !== null){ |
|
| 139 | 139 | $route = $route->withMiddleware(...$configurator->middleware); |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - if ($configurator->methods !== null) { |
|
| 142 | + if ($configurator->methods !== null){ |
|
| 143 | 143 | $route = $route->withVerbs(...$configurator->methods); |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - if (!isset($this->routes[$name]) && $name !== RoutingConfigurator::DEFAULT_ROUTE_NAME) { |
|
| 146 | + if (!isset($this->routes[$name]) && $name !== RoutingConfigurator::DEFAULT_ROUTE_NAME){ |
|
| 147 | 147 | $groups->getGroup($configurator->group ?? $groups->getDefaultGroup())->addRoute($name, $route); |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - if ($name === RoutingConfigurator::DEFAULT_ROUTE_NAME) { |
|
| 150 | + if ($name === RoutingConfigurator::DEFAULT_ROUTE_NAME){ |
|
| 151 | 151 | $this->setDefault($route); |
| 152 | 152 | } |
| 153 | 153 | } |
@@ -158,17 +158,17 @@ discard block |
||
| 158 | 158 | */ |
| 159 | 159 | protected function matchRoute(ServerRequestInterface $request, string &$routeName = null): ?RouteInterface |
| 160 | 160 | { |
| 161 | - foreach ($this->routes as $name => $route) { |
|
| 161 | + foreach ($this->routes as $name => $route){ |
|
| 162 | 162 | // Matched route will return new route instance with matched parameters |
| 163 | 163 | $matched = $route->match($request); |
| 164 | 164 | |
| 165 | - if ($matched !== null) { |
|
| 165 | + if ($matched !== null){ |
|
| 166 | 166 | $routeName = $name; |
| 167 | 167 | return $matched; |
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - if ($this->default !== null) { |
|
| 171 | + if ($this->default !== null){ |
|
| 172 | 172 | return $this->default->match($request); |
| 173 | 173 | } |
| 174 | 174 | |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | */ |
| 182 | 182 | protected function configure(RouteInterface $route): RouteInterface |
| 183 | 183 | { |
| 184 | - if ($route instanceof ContainerizedInterface && !$route->hasContainer()) { |
|
| 184 | + if ($route instanceof ContainerizedInterface && !$route->hasContainer()){ |
|
| 185 | 185 | // isolating route in a given container |
| 186 | 186 | $route = $route->withContainer($this->container); |
| 187 | 187 | } |
@@ -205,17 +205,17 @@ discard block |
||
| 205 | 205 | $route, |
| 206 | 206 | $matches |
| 207 | 207 | ) |
| 208 | - ) { |
|
| 208 | + ){ |
|
| 209 | 209 | throw new UndefinedRouteException( |
| 210 | 210 | "Unable to locate route or use default route with 'name/controller:action' pattern" |
| 211 | 211 | ); |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - if (!empty($matches['name'])) { |
|
| 214 | + if (!empty($matches['name'])){ |
|
| 215 | 215 | $routeObject = $this->getRoute($matches['name']); |
| 216 | - } elseif ($this->default !== null) { |
|
| 216 | + } elseif ($this->default !== null){ |
|
| 217 | 217 | $routeObject = $this->default; |
| 218 | - } else { |
|
| 218 | + }else{ |
|
| 219 | 219 | throw new UndefinedRouteException(\sprintf('Unable to locate route candidate for `%s`', $route)); |
| 220 | 220 | } |
| 221 | 221 | |
@@ -57,13 +57,17 @@ discard block |
||
| 57 | 57 | { |
| 58 | 58 | $this->eventDispatcher?->dispatch(new Routing($request)); |
| 59 | 59 | |
| 60 | - try { |
|
| 60 | + try |
|
| 61 | + { |
|
| 61 | 62 | $route = $this->matchRoute($request, $routeName); |
| 62 | - } catch (RouteException $e) { |
|
| 63 | + } |
|
| 64 | + catch (RouteException $e) |
|
| 65 | + { |
|
| 63 | 66 | throw new RouterException('Invalid route definition', $e->getCode(), $e); |
| 64 | 67 | } |
| 65 | 68 | |
| 66 | - if ($route === null) { |
|
| 69 | + if ($route === null) |
|
| 70 | + { |
|
| 67 | 71 | $this->eventDispatcher?->dispatch(new RouteNotFound($request)); |
| 68 | 72 | throw new RouteNotFoundException($request->getUri()); |
| 69 | 73 | } |
@@ -91,7 +95,8 @@ discard block |
||
| 91 | 95 | |
| 92 | 96 | public function getRoute(string $name): RouteInterface |
| 93 | 97 | { |
| 94 | - if (isset($this->routes[$name])) { |
|
| 98 | + if (isset($this->routes[$name])) |
|
| 99 | + { |
|
| 95 | 100 | return $this->routes[$name]; |
| 96 | 101 | } |
| 97 | 102 | |
@@ -100,7 +105,8 @@ discard block |
||
| 100 | 105 | |
| 101 | 106 | public function getRoutes(): array |
| 102 | 107 | { |
| 103 | - if (!empty($this->default)) { |
|
| 108 | + if (!empty($this->default)) |
|
| 109 | + { |
|
| 104 | 110 | return $this->routes + [null => $this->default]; |
| 105 | 111 | } |
| 106 | 112 | |
@@ -109,9 +115,12 @@ discard block |
||
| 109 | 115 | |
| 110 | 116 | public function uri(string $route, iterable $parameters = []): UriInterface |
| 111 | 117 | { |
| 112 | - try { |
|
| 118 | + try |
|
| 119 | + { |
|
| 113 | 120 | return $this->getRoute($route)->uri($parameters); |
| 114 | - } catch (UndefinedRouteException) { |
|
| 121 | + } |
|
| 122 | + catch (UndefinedRouteException) |
|
| 123 | + { |
|
| 115 | 124 | //In some cases route name can be provided as controller:action pair, we can try to |
| 116 | 125 | //generate such route automatically based on our default/fallback route |
| 117 | 126 | return $this->castRoute($route)->uri($parameters); |
@@ -123,9 +132,11 @@ discard block |
||
| 123 | 132 | /** @var GroupRegistry $groups */ |
| 124 | 133 | $groups = $this->container->get(GroupRegistry::class); |
| 125 | 134 | |
| 126 | - foreach ($routes->getCollection() as $name => $configurator) { |
|
| 135 | + foreach ($routes->getCollection() as $name => $configurator) |
|
| 136 | + { |
|
| 127 | 137 | $target = $configurator->target; |
| 128 | - if ($configurator->core !== null && $target instanceof AbstractTarget) { |
|
| 138 | + if ($configurator->core !== null && $target instanceof AbstractTarget) |
|
| 139 | + { |
|
| 129 | 140 | $target = $target->withCore($configurator->core); |
| 130 | 141 | } |
| 131 | 142 | |
@@ -135,19 +146,23 @@ discard block |
||
| 135 | 146 | $configurator->defaults |
| 136 | 147 | ); |
| 137 | 148 | |
| 138 | - if ($configurator->middleware !== null) { |
|
| 149 | + if ($configurator->middleware !== null) |
|
| 150 | + { |
|
| 139 | 151 | $route = $route->withMiddleware(...$configurator->middleware); |
| 140 | 152 | } |
| 141 | 153 | |
| 142 | - if ($configurator->methods !== null) { |
|
| 154 | + if ($configurator->methods !== null) |
|
| 155 | + { |
|
| 143 | 156 | $route = $route->withVerbs(...$configurator->methods); |
| 144 | 157 | } |
| 145 | 158 | |
| 146 | - if (!isset($this->routes[$name]) && $name !== RoutingConfigurator::DEFAULT_ROUTE_NAME) { |
|
| 159 | + if (!isset($this->routes[$name]) && $name !== RoutingConfigurator::DEFAULT_ROUTE_NAME) |
|
| 160 | + { |
|
| 147 | 161 | $groups->getGroup($configurator->group ?? $groups->getDefaultGroup())->addRoute($name, $route); |
| 148 | 162 | } |
| 149 | 163 | |
| 150 | - if ($name === RoutingConfigurator::DEFAULT_ROUTE_NAME) { |
|
| 164 | + if ($name === RoutingConfigurator::DEFAULT_ROUTE_NAME) |
|
| 165 | + { |
|
| 151 | 166 | $this->setDefault($route); |
| 152 | 167 | } |
| 153 | 168 | } |
@@ -158,17 +173,20 @@ discard block |
||
| 158 | 173 | */ |
| 159 | 174 | protected function matchRoute(ServerRequestInterface $request, string &$routeName = null): ?RouteInterface |
| 160 | 175 | { |
| 161 | - foreach ($this->routes as $name => $route) { |
|
| 176 | + foreach ($this->routes as $name => $route) |
|
| 177 | + { |
|
| 162 | 178 | // Matched route will return new route instance with matched parameters |
| 163 | 179 | $matched = $route->match($request); |
| 164 | 180 | |
| 165 | - if ($matched !== null) { |
|
| 181 | + if ($matched !== null) |
|
| 182 | + { |
|
| 166 | 183 | $routeName = $name; |
| 167 | 184 | return $matched; |
| 168 | 185 | } |
| 169 | 186 | } |
| 170 | 187 | |
| 171 | - if ($this->default !== null) { |
|
| 188 | + if ($this->default !== null) |
|
| 189 | + { |
|
| 172 | 190 | return $this->default->match($request); |
| 173 | 191 | } |
| 174 | 192 | |
@@ -181,7 +199,8 @@ discard block |
||
| 181 | 199 | */ |
| 182 | 200 | protected function configure(RouteInterface $route): RouteInterface |
| 183 | 201 | { |
| 184 | - if ($route instanceof ContainerizedInterface && !$route->hasContainer()) { |
|
| 202 | + if ($route instanceof ContainerizedInterface && !$route->hasContainer()) |
|
| 203 | + { |
|
| 185 | 204 | // isolating route in a given container |
| 186 | 205 | $route = $route->withContainer($this->container); |
| 187 | 206 | } |
@@ -211,11 +230,16 @@ discard block |
||
| 211 | 230 | ); |
| 212 | 231 | } |
| 213 | 232 | |
| 214 | - if (!empty($matches['name'])) { |
|
| 233 | + if (!empty($matches['name'])) |
|
| 234 | + { |
|
| 215 | 235 | $routeObject = $this->getRoute($matches['name']); |
| 216 | - } elseif ($this->default !== null) { |
|
| 236 | + } |
|
| 237 | + elseif ($this->default !== null) |
|
| 238 | + { |
|
| 217 | 239 | $routeObject = $this->default; |
| 218 | - } else { |
|
| 240 | + } |
|
| 241 | + else |
|
| 242 | + { |
|
| 219 | 243 | throw new UndefinedRouteException(\sprintf('Unable to locate route candidate for `%s`', $route)); |
| 220 | 244 | } |
| 221 | 245 | |
@@ -50,9 +50,9 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | public function __construct( |
| 52 | 52 | string $pattern, |
| 53 | - string|callable|RequestHandlerInterface|TargetInterface $target, |
|
| 53 | + string | callable | RequestHandlerInterface | TargetInterface $target, |
|
| 54 | 54 | array $defaults = [] |
| 55 | - ) { |
|
| 55 | + ){ |
|
| 56 | 56 | parent::__construct( |
| 57 | 57 | $pattern, |
| 58 | 58 | $target instanceof TargetInterface |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | public function withUriHandler(UriHandler $uriHandler): static |
| 67 | 67 | { |
| 68 | 68 | $route = parent::withUriHandler($uriHandler); |
| 69 | - if ($this->target instanceof TargetInterface) { |
|
| 69 | + if ($this->target instanceof TargetInterface){ |
|
| 70 | 70 | $route->uriHandler = $route->uriHandler->withConstrains( |
| 71 | 71 | $this->target->getConstrains(), |
| 72 | 72 | $this->defaults |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | $route = clone $this; |
| 85 | 85 | $route->container = $container; |
| 86 | 86 | |
| 87 | - if ($route->target instanceof TargetInterface) { |
|
| 87 | + if ($route->target instanceof TargetInterface){ |
|
| 88 | 88 | $route->target = clone $route->target; |
| 89 | 89 | } |
| 90 | 90 | |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | public function handle(ServerRequestInterface $request): ResponseInterface |
| 113 | 113 | { |
| 114 | - if (empty($this->requestHandler)) { |
|
| 114 | + if (empty($this->requestHandler)){ |
|
| 115 | 115 | $this->requestHandler = $this->requestHandler(); |
| 116 | 116 | } |
| 117 | 117 | |
@@ -126,28 +126,28 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | protected function requestHandler(): RequestHandlerInterface |
| 128 | 128 | { |
| 129 | - if (!$this->hasContainer()) { |
|
| 129 | + if (!$this->hasContainer()){ |
|
| 130 | 130 | throw new RouteException('Unable to configure route pipeline without associated container'); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - if ($this->target instanceof TargetInterface) { |
|
| 134 | - try { |
|
| 133 | + if ($this->target instanceof TargetInterface){ |
|
| 134 | + try{ |
|
| 135 | 135 | return $this->target->getHandler($this->container, $this->matches); |
| 136 | - } catch (TargetException $e) { |
|
| 136 | + }catch (TargetException $e){ |
|
| 137 | 137 | throw new RouteException('Invalid target resolution', $e->getCode(), $e); |
| 138 | 138 | } |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - if ($this->target instanceof RequestHandlerInterface) { |
|
| 141 | + if ($this->target instanceof RequestHandlerInterface){ |
|
| 142 | 142 | return $this->target; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - try { |
|
| 145 | + try{ |
|
| 146 | 146 | $target = \is_string($this->target) |
| 147 | 147 | ? $this->container->get($this->target) |
| 148 | 148 | : $this->target; |
| 149 | 149 | |
| 150 | - if ($target instanceof RequestHandlerInterface) { |
|
| 150 | + if ($target instanceof RequestHandlerInterface){ |
|
| 151 | 151 | return $target; |
| 152 | 152 | } |
| 153 | 153 | |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | $target, |
| 156 | 156 | $this->container->get(ResponseFactoryInterface::class) |
| 157 | 157 | ); |
| 158 | - } catch (ContainerExceptionInterface $e) { |
|
| 158 | + }catch (ContainerExceptionInterface $e){ |
|
| 159 | 159 | throw new RouteException($e->getMessage(), $e->getCode(), $e); |
| 160 | 160 | } |
| 161 | 161 | } |
@@ -66,7 +66,8 @@ discard block |
||
| 66 | 66 | public function withUriHandler(UriHandler $uriHandler): static |
| 67 | 67 | { |
| 68 | 68 | $route = parent::withUriHandler($uriHandler); |
| 69 | - if ($this->target instanceof TargetInterface) { |
|
| 69 | + if ($this->target instanceof TargetInterface) |
|
| 70 | + { |
|
| 70 | 71 | $route->uriHandler = $route->uriHandler->withConstrains( |
| 71 | 72 | $this->target->getConstrains(), |
| 72 | 73 | $this->defaults |
@@ -84,7 +85,8 @@ discard block |
||
| 84 | 85 | $route = clone $this; |
| 85 | 86 | $route->container = $container; |
| 86 | 87 | |
| 87 | - if ($route->target instanceof TargetInterface) { |
|
| 88 | + if ($route->target instanceof TargetInterface) |
|
| 89 | + { |
|
| 88 | 90 | $route->target = clone $route->target; |
| 89 | 91 | } |
| 90 | 92 | |
@@ -111,7 +113,8 @@ discard block |
||
| 111 | 113 | */ |
| 112 | 114 | public function handle(ServerRequestInterface $request): ResponseInterface |
| 113 | 115 | { |
| 114 | - if (empty($this->requestHandler)) { |
|
| 116 | + if (empty($this->requestHandler)) |
|
| 117 | + { |
|
| 115 | 118 | $this->requestHandler = $this->requestHandler(); |
| 116 | 119 | } |
| 117 | 120 | |
@@ -126,28 +129,36 @@ discard block |
||
| 126 | 129 | */ |
| 127 | 130 | protected function requestHandler(): RequestHandlerInterface |
| 128 | 131 | { |
| 129 | - if (!$this->hasContainer()) { |
|
| 132 | + if (!$this->hasContainer()) |
|
| 133 | + { |
|
| 130 | 134 | throw new RouteException('Unable to configure route pipeline without associated container'); |
| 131 | 135 | } |
| 132 | 136 | |
| 133 | - if ($this->target instanceof TargetInterface) { |
|
| 134 | - try { |
|
| 137 | + if ($this->target instanceof TargetInterface) |
|
| 138 | + { |
|
| 139 | + try |
|
| 140 | + { |
|
| 135 | 141 | return $this->target->getHandler($this->container, $this->matches); |
| 136 | - } catch (TargetException $e) { |
|
| 142 | + } |
|
| 143 | + catch (TargetException $e) |
|
| 144 | + { |
|
| 137 | 145 | throw new RouteException('Invalid target resolution', $e->getCode(), $e); |
| 138 | 146 | } |
| 139 | 147 | } |
| 140 | 148 | |
| 141 | - if ($this->target instanceof RequestHandlerInterface) { |
|
| 149 | + if ($this->target instanceof RequestHandlerInterface) |
|
| 150 | + { |
|
| 142 | 151 | return $this->target; |
| 143 | 152 | } |
| 144 | 153 | |
| 145 | - try { |
|
| 154 | + try |
|
| 155 | + { |
|
| 146 | 156 | $target = \is_string($this->target) |
| 147 | 157 | ? $this->container->get($this->target) |
| 148 | 158 | : $this->target; |
| 149 | 159 | |
| 150 | - if ($target instanceof RequestHandlerInterface) { |
|
| 160 | + if ($target instanceof RequestHandlerInterface) |
|
| 161 | + { |
|
| 151 | 162 | return $target; |
| 152 | 163 | } |
| 153 | 164 | |
@@ -155,7 +166,9 @@ discard block |
||
| 155 | 166 | $target, |
| 156 | 167 | $this->container->get(ResponseFactoryInterface::class) |
| 157 | 168 | ); |
| 158 | - } catch (ContainerExceptionInterface $e) { |
|
| 169 | + } |
|
| 170 | + catch (ContainerExceptionInterface $e) |
|
| 171 | + { |
|
| 159 | 172 | throw new RouteException($e->getMessage(), $e->getCode(), $e); |
| 160 | 173 | } |
| 161 | 174 | } |
@@ -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 |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | public function __clone() |
| 15 | 15 | { |
| 16 | - foreach ($this->routes as $name => $route) { |
|
| 16 | + foreach ($this->routes as $name => $route){ |
|
| 17 | 17 | $this->routes[$name] = clone $route; |
| 18 | 18 | } |
| 19 | 19 | } |
@@ -72,16 +72,16 @@ discard block |
||
| 72 | 72 | * |
| 73 | 73 | * @param string|string[] $name The route name or an array of route names |
| 74 | 74 | */ |
| 75 | - public function remove(string|array $name) |
|
| 75 | + public function remove(string | array $name) |
|
| 76 | 76 | { |
| 77 | - foreach ((array) $name as $n) { |
|
| 77 | + foreach ((array)$name as $n){ |
|
| 78 | 78 | unset($this->routes[$n]); |
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | public function addCollection(self $collection) |
| 83 | 83 | { |
| 84 | - foreach ($collection->all() as $name => $route) { |
|
| 84 | + foreach ($collection->all() as $name => $route){ |
|
| 85 | 85 | $this->routes[$name] = $route; |
| 86 | 86 | } |
| 87 | 87 | } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | public function group(string $group) |
| 93 | 93 | { |
| 94 | - foreach ($this->routes as $route) { |
|
| 94 | + foreach ($this->routes as $route){ |
|
| 95 | 95 | $route->group($group); |
| 96 | 96 | } |
| 97 | 97 | } |
@@ -13,7 +13,8 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | public function __clone() |
| 15 | 15 | { |
| 16 | - foreach ($this->routes as $name => $route) { |
|
| 16 | + foreach ($this->routes as $name => $route) |
|
| 17 | + { |
|
| 17 | 18 | $this->routes[$name] = clone $route; |
| 18 | 19 | } |
| 19 | 20 | } |
@@ -74,14 +75,16 @@ discard block |
||
| 74 | 75 | */ |
| 75 | 76 | public function remove(string|array $name) |
| 76 | 77 | { |
| 77 | - foreach ((array) $name as $n) { |
|
| 78 | + foreach ((array) $name as $n) |
|
| 79 | + { |
|
| 78 | 80 | unset($this->routes[$n]); |
| 79 | 81 | } |
| 80 | 82 | } |
| 81 | 83 | |
| 82 | 84 | public function addCollection(self $collection) |
| 83 | 85 | { |
| 84 | - foreach ($collection->all() as $name => $route) { |
|
| 86 | + foreach ($collection->all() as $name => $route) |
|
| 87 | + { |
|
| 85 | 88 | $this->routes[$name] = $route; |
| 86 | 89 | } |
| 87 | 90 | } |
@@ -91,7 +94,8 @@ discard block |
||
| 91 | 94 | */ |
| 92 | 95 | public function group(string $group) |
| 93 | 96 | { |
| 94 | - foreach ($this->routes as $route) { |
|
| 97 | + foreach ($this->routes as $route) |
|
| 98 | + { |
|
| 95 | 99 | $route->group($group); |
| 96 | 100 | } |
| 97 | 101 | } |
@@ -19,9 +19,9 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | public function withVerbs(string ...$verbs): RouteInterface |
| 21 | 21 | { |
| 22 | - foreach ($verbs as &$verb) { |
|
| 22 | + foreach ($verbs as &$verb){ |
|
| 23 | 23 | $verb = \strtoupper($verb); |
| 24 | - if (!\in_array($verb, RouteInterface::VERBS, true)) { |
|
| 24 | + if (!\in_array($verb, RouteInterface::VERBS, true)){ |
|
| 25 | 25 | throw new RouteException(\sprintf('Invalid HTTP verb `%s`', $verb)); |
| 26 | 26 | } |
| 27 | 27 | |
@@ -19,9 +19,11 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | public function withVerbs(string ...$verbs): RouteInterface |
| 21 | 21 | { |
| 22 | - foreach ($verbs as &$verb) { |
|
| 22 | + foreach ($verbs as &$verb) |
|
| 23 | + { |
|
| 23 | 24 | $verb = \strtoupper($verb); |
| 24 | - if (!\in_array($verb, RouteInterface::VERBS, true)) { |
|
| 25 | + if (!\in_array($verb, RouteInterface::VERBS, true)) |
|
| 26 | + { |
|
| 25 | 27 | throw new RouteException(\sprintf('Invalid HTTP verb `%s`', $verb)); |
| 26 | 28 | } |
| 27 | 29 | |
@@ -42,16 +42,16 @@ discard block |
||
| 42 | 42 | $route = clone $this; |
| 43 | 43 | |
| 44 | 44 | // array fallback |
| 45 | - if (\count($middleware) === 1 && \is_array($middleware[0])) { |
|
| 45 | + if (\count($middleware) === 1 && \is_array($middleware[0])){ |
|
| 46 | 46 | $middleware = $middleware[0]; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** @var MiddlewareType[] $middleware */ |
| 50 | - foreach ($middleware as $item) { |
|
| 50 | + foreach ($middleware as $item){ |
|
| 51 | 51 | $route->middleware[] = $item; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - if ($route->pipeline !== null) { |
|
| 54 | + if ($route->pipeline !== null){ |
|
| 55 | 55 | $route->pipeline = $route->makePipeline(); |
| 56 | 56 | } |
| 57 | 57 | |
@@ -75,11 +75,11 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | protected function makePipeline(): Pipeline |
| 77 | 77 | { |
| 78 | - try { |
|
| 78 | + try{ |
|
| 79 | 79 | return $this->container |
| 80 | 80 | ->get(PipelineFactory::class) |
| 81 | 81 | ->createWithMiddleware($this->middleware); |
| 82 | - } catch (ContainerExceptionInterface $e) { |
|
| 82 | + }catch (ContainerExceptionInterface $e){ |
|
| 83 | 83 | throw new RouteException($e->getMessage(), $e->getCode(), $e); |
| 84 | 84 | } |
| 85 | 85 | } |
@@ -42,16 +42,19 @@ discard block |
||
| 42 | 42 | $route = clone $this; |
| 43 | 43 | |
| 44 | 44 | // array fallback |
| 45 | - if (\count($middleware) === 1 && \is_array($middleware[0])) { |
|
| 45 | + if (\count($middleware) === 1 && \is_array($middleware[0])) |
|
| 46 | + { |
|
| 46 | 47 | $middleware = $middleware[0]; |
| 47 | 48 | } |
| 48 | 49 | |
| 49 | 50 | /** @var MiddlewareType[] $middleware */ |
| 50 | - foreach ($middleware as $item) { |
|
| 51 | + foreach ($middleware as $item) |
|
| 52 | + { |
|
| 51 | 53 | $route->middleware[] = $item; |
| 52 | 54 | } |
| 53 | 55 | |
| 54 | - if ($route->pipeline !== null) { |
|
| 56 | + if ($route->pipeline !== null) |
|
| 57 | + { |
|
| 55 | 58 | $route->pipeline = $route->makePipeline(); |
| 56 | 59 | } |
| 57 | 60 | |
@@ -75,11 +78,14 @@ discard block |
||
| 75 | 78 | */ |
| 76 | 79 | protected function makePipeline(): Pipeline |
| 77 | 80 | { |
| 78 | - try { |
|
| 81 | + try |
|
| 82 | + { |
|
| 79 | 83 | return $this->container |
| 80 | 84 | ->get(PipelineFactory::class) |
| 81 | 85 | ->createWithMiddleware($this->middleware); |
| 82 | - } catch (ContainerExceptionInterface $e) { |
|
| 86 | + } |
|
| 87 | + catch (ContainerExceptionInterface $e) |
|
| 88 | + { |
|
| 83 | 89 | throw new RouteException($e->getMessage(), $e->getCode(), $e); |
| 84 | 90 | } |
| 85 | 91 | } |
@@ -10,6 +10,6 @@ |
||
| 10 | 10 | { |
| 11 | 11 | public function __construct( |
| 12 | 12 | public readonly ServerRequestInterface $request |
| 13 | - ) { |
|
| 13 | + ){ |
|
| 14 | 14 | } |
| 15 | 15 | } |
@@ -12,6 +12,6 @@ |
||
| 12 | 12 | public function __construct( |
| 13 | 13 | public readonly ServerRequestInterface $request, |
| 14 | 14 | public readonly RouteInterface $route, |
| 15 | - ) { |
|
| 15 | + ){ |
|
| 16 | 16 | } |
| 17 | 17 | } |