-
Notifications
You must be signed in to change notification settings - Fork 38
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
Support for typed route parameters #69
Comments
I think in Slim mechanics it would make sense to restrict the route to numeric IDs, so invalid value doesn't even match/reach controller: $app->delete("/objects/{objectId:[0-9]+}", [MyController::class, 'deleteObject']); See regular expression matching. You'll get an automatic native 404 from Slim, for anything that doesn't match. Not sure how invocation could be any "smarter" about such. I think it's already better than native Slim for types (Slim wouldn't even cast input to |
This is definitely not an issue that concerns |
@fabiante What you want is solved by writing an invocation route strategy, see the Slim docs. If you dont want to learn the Slim internals - you can use my component for the Slim (https://github.com/solventt/slim-route-strategy) - It also solves your problem: a numeric |
Hi!
I'd like to use php-di to inject route parameters. In my case these are always of type
int
.Using this function signature ...
... and then calling the path of this function with this URL:
DELETE /objects/testing/
...... produces a standard PHP exception:
Argument 4 passed to App\\Controllers\\v2\\DocumentClassController::deleteTableField() must be of the type int, string given
I do understand why this happens and of course I could remove the
int
type from the function signature and perform my own validation. But' maybe I am missing a more elegant way to catch this exception and automatically respond with a400
status code.The text was updated successfully, but these errors were encountered: