Skip to content
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

fix: add strict mode for UriHandler #1192

Merged
merged 5 commits into from
Jan 22, 2025
Merged

fix: add strict mode for UriHandler #1192

merged 5 commits into from
Jan 22, 2025

Conversation

butschster
Copy link
Member

@butschster butschster commented Jan 6, 2025

Strict mode ensures all required URI segments are validated. If any are missing, an exception is thrown.

To enable strict mode, request Spiral\Router\UriHandler from the container in RoutersBootloader and set strict mode:

$handler = $container->get(\Spiral\Router\UriHandler::class);
$handler->setStrict(true);
Q A
Bugfix? ✔️
Breaks BC?
New feature? ✔️
Issues #1162

When it's turned on, the handler will check all required URI segments and throw an exception if any are missing.
This helps catch incomplete routes early and makes sure all params are present.
@butschster butschster added this to the 3.14 milestone Jan 6, 2025
@butschster butschster requested a review from roxblnfk January 6, 2025 08:11
@butschster butschster self-assigned this Jan 6, 2025
- Removes empty segments for optional parameters
- Adds more patters for unit tests
if ($missingParameters !== []) {
throw new UriHandlerException(
\sprintf(
\count($missingParameters) === 1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor error message

@roxblnfk roxblnfk modified the milestones: 3.14, 3.15 Jan 21, 2025
@roxblnfk roxblnfk merged commit 2ee5471 into master Jan 22, 2025
9 checks passed
@roxblnfk roxblnfk deleted the issue/1162 branch January 22, 2025 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[spiral/router] Required parameters are not required for uri generation
2 participants