-
-
Notifications
You must be signed in to change notification settings - Fork 2k
v5 - Refactor routing to use RouteMatch and dispatcher interfaces #3438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Slim\Interfaces; | ||
|
|
||
| interface DispatcherInterface | ||
| { | ||
| const NOT_FOUND = 0; | ||
| const FOUND = 1; | ||
| const METHOD_NOT_ALLOWED = 2; | ||
|
|
||
| /** | ||
| * @return array<int, mixed> | ||
| */ | ||
| public function dispatch(string $httpMethod, string $uri): array; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Slim Framework (https://slimframework.com) | ||
| * | ||
| * @license https://github.com/slimphp/Slim/blob/5.x/LICENSE.md (MIT License) | ||
| */ | ||
|
|
||
| namespace Slim\Interfaces; | ||
|
|
||
| use Psr\Http\Server\MiddlewareInterface; | ||
| use Slim\Routing\RouteGroup; | ||
|
|
||
| interface RouteInterface | ||
| { | ||
| /** | ||
| * Get route callable. | ||
| * | ||
| * @return callable|string | ||
| */ | ||
| public function getHandler(): callable|string; | ||
|
|
||
| /** | ||
| * Set route name. | ||
| * | ||
| * @param string $name The route name | ||
| * | ||
| * @return RouteInterface | ||
| */ | ||
| public function setName(string $name): RouteInterface; | ||
|
|
||
| /** | ||
| * Get route name. | ||
| */ | ||
| public function getName(): ?string; | ||
|
|
||
| /** | ||
| * Get route pattern. | ||
| * | ||
| * @return string | ||
| */ | ||
| public function getPattern(): string; | ||
|
|
||
| /** | ||
| * Get route HTTP methods | ||
| * | ||
| * @return array<string> | ||
| */ | ||
| public function getMethods(): array; | ||
|
|
||
| /** | ||
| * Get route group. | ||
| * | ||
| * @return RouteGroup|null | ||
| */ | ||
| public function getRouteGroup(): ?RouteGroup; | ||
|
|
||
| /** | ||
| * Retrieve a specific route argument. | ||
| */ | ||
| public function getArgument(string $name, ?string $default = null): ?string; | ||
|
|
||
| /** | ||
| * Get route arguments. | ||
| * | ||
| * @return array<string, string> | ||
| */ | ||
| public function getArguments(): array; | ||
|
|
||
| /** | ||
| * Set route arguments. | ||
| * | ||
| * @param array<string,mixed> $arguments The arguments. | ||
| * | ||
| * @return RouteInterface | ||
| */ | ||
| public function setArguments(array $arguments): RouteInterface; | ||
|
|
||
| /** | ||
| * @return array<MiddlewareInterface|callable|string> | ||
| */ | ||
| public function getMiddleware(): array; | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -15,7 +15,6 @@ | |||
| use Psr\Http\Server\MiddlewareInterface; | ||||
| use Psr\Http\Server\RequestHandlerInterface; | ||||
| use Slim\Interfaces\RouterInterface; | ||||
| use Slim\Routing\RouteContext; | ||||
|
|
||||
| final class BasePathMiddleware implements MiddlewareInterface | ||||
| { | ||||
|
|
@@ -46,7 +45,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface | |||
| $basePath = $this->getBasePathByRequestUri($request); | ||||
| } | ||||
|
|
||||
| $request = $request->withAttribute(RouteContext::BASE_PATH, $basePath); | ||||
| // $request = $request->withAttribute(RouteMatch::BASE_PATH_ATTRIBUTE, $basePath); | ||||
|
|
||||
|
Comment on lines
+48
to
49
|
||||
| // $request = $request->withAttribute(RouteMatch::BASE_PATH_ATTRIBUTE, $basePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
RouteInterfaceargument APIs are internally inconsistent:getArgument()/getArguments()are documented/typed as returning strings, butsetArguments()documentsarray<string, mixed>. Either restrictsetArguments()toarray<string, string>(and enforce/validate) or widen the getters’ types/docs so callers aren’t misled.