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

A non-matching METHOD is 'METHOD_NOT_ALLOWED' on static routes #50

Closed
terah opened this issue May 15, 2015 · 4 comments
Closed

A non-matching METHOD is 'METHOD_NOT_ALLOWED' on static routes #50

terah opened this issue May 15, 2015 · 4 comments

Comments

@terah
Copy link

terah commented May 15, 2015

In this example performing the request 'GET /users.json' the static route /users.json matches the request and returns METHOD_NOT_ALLOWED. Shouldn't the GET /{entity}.json route match the request?

<?php

require '/path/to/FastRoute/src/bootstrap.php';

$dispatcher = FastRoute\simpleDispatcher(function(FastRoute\RouteCollector $r) {
    $r->addRoute('POST', '/user.json', 'postHandler');
    $r->addRoute('GET', '/{entity}.json', 'getHandler');
});

$routeInfo = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);
switch ($routeInfo[0]) {
    case FastRoute\Dispatcher::NOT_FOUND:
        break;
    case FastRoute\Dispatcher::METHOD_NOT_ALLOWED:
        $allowedMethods = $routeInfo[1];
        // ... 405 Method Not Allowed
        print_r($routeInfo);
        echo "METHOD NOT ALLOWED";
        die(405);
        break;
    case FastRoute\Dispatcher::FOUND:
        $handler = $routeInfo[1];
        $vars = $routeInfo[2];
        // ... call $handler with $vars
        break;
}
exit;
@nikic
Copy link
Owner

nikic commented May 15, 2015

Yeah, /{entity}.json should match. This is the same problem as #25, looks like I forgot to fix it for the case of static routes.

nikic added a commit that referenced this issue May 15, 2015
If the static route doesn't exist for the given method, try matching
against dynamic ones as well. Allowed methods are now collected from
both static and dynamic routes.

This changes the route data format, so cache is no longer valid --
maybe include a version identifier in the cache file?
@nikic
Copy link
Owner

nikic commented May 15, 2015

Should be fixed now.

@nikic nikic closed this as completed May 15, 2015
@terah
Copy link
Author

terah commented May 19, 2015

Thanks for the fast response! <-see what I did there?

@joshdevkit
Copy link

how can we show the actual controller name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants