-
Notifications
You must be signed in to change notification settings - Fork 448
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
Feature request: Retrieve allowed method for route #148
Comments
Sounds like a reasonable feature, and the code is basically all there already: https://github.com/nikic/FastRoute/blob/master/src/Dispatcher/RegexBasedAbstract.php#L59 Adding a method to the |
Wouldn't you introduce another interface to allow addition of methods though? That would be the more SOLID way of doing it. Something like |
I have a question regarding the method and URI. Look at the 405 definition:
It seems that you have to first find the target resource and then check what methods can be used on it. In Have you considered such a way of dispatching -- where first you try to find a match against the $uri, and then check what methods are allowed for it? It seems that with this approach you will have to traverse the route collection only once as there will be no need to check multiple times -- like when checking for HEAD or for fallback routes or for the allowed method. Once there is a match you will know what methods are associated with that route and can use them for the allowed method header. This will also solve that initial comment request about fetching what methods are associated with a route. |
@kktsvetkov that's kind of the direction I'm going with #244. There are some small important things to be addressed (the pattern matching gets a bit more complicated) |
I'm preparing CORS middleware for REST API, which is appending list of allowed methods to a preflight request route.
As I'm using Slim framework v3, this is not possible append middleware headers in the notAllowed error handler (which is aware of allowed methods) as error handlers don't trigger middlewares.
Suggested way to do it to collect all methods for with same endpoint in the application using strict comparison which doesn't patterns.
My workaround is to create a fake request, dispatch route and collect allowed methods from router:
What I'm looking for is a helper function on dispatcher
The text was updated successfully, but these errors were encountered: