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

MethodNotAllowed is thrown when not needed and vice versa #50

Closed
rept1d opened this issue Feb 6, 2020 · 2 comments
Closed

MethodNotAllowed is thrown when not needed and vice versa #50

rept1d opened this issue Feb 6, 2020 · 2 comments
Assignees
Labels

Comments

@rept1d
Copy link

rept1d commented Feb 6, 2020

According to the following code in Router::match

$routes = [];
foreach ($this->routes as $route) {
    foreach ($route->getMethods() as $method) {
        $routes[$method][] = $route;
    }
}

$method = $request->getMethod();
if (!isset($routes[$method])) {
    $errmsg = sprintf('The method "%s" is not allowed.', $method);

    throw new MethodNotAllowedException($errmsg, [
        'allowed' => array_keys($routes),
    ]);
}

MethodNotAllowedException is thrown depending on the list of HTTP Methods from all the routes bound to the Router instead of being based on URL.

This leads to the following cases when it seems like the router doesn't work as intended:

  1. On requesting a nonexistent route (path) one can get MethodNotAllowedException being throwpn (instead of RouteNotFoundException) if the requesting method is not found at any of registered routes.
  2. On requesting a registered route (path) using the method that is not supported by that route one can get no exception being thrown if that method is present anywhere else.

You can also check RFC to make sure that the current behavior is improper.

@fenric fenric self-assigned this Feb 6, 2020
@fenric fenric added the feature label Feb 6, 2020
@fenric
Copy link
Member

fenric commented Feb 6, 2020

it's solution for fast matching... the 1.x version contains an other solution...

I can add a new method to the router to switch the match logic (strategy)...

fenric added a commit that referenced this issue Apr 20, 2020
@fenric fenric mentioned this issue Apr 20, 2020
@fenric
Copy link
Member

fenric commented Apr 20, 2020

thanks for your interest! see version 2.4.

@fenric fenric closed this as completed Apr 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants