Skip to content

Conversation

@papparazzo
Copy link
Contributor

If you create two routes, one with a static path and the other one with a placeholder
and call "getAllowedMethods" from Slim/Routing/FastRouteDispatcher.php afterwards, the same method is returned twice, because one route is set in staticRouteMap while the other one is set in variableRouteData.

Please see example below for further information

composer.json:

{
    "require": {
        "slim/slim": "^4.11",
        "slim/http": "^1.3",
        "slim/psr7": "^1.6"
    }
}

public/index.php:

<?php

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
use Slim\Routing\RouteContext;

require __DIR__ . '/../vendor/autoload.php';

$app = AppFactory::create();

$app->get('/name', function (Request $request, Response $response) {
    $rr = RouteContext::fromRequest($request)->getRoutingResults();
    var_dump($rr->getDispatcher()->getAllowedMethods($rr->getUri()));
    return $response;
});

$app->get('/{name}', function (Request $request, Response $response) {
    $rr = RouteContext::fromRequest($request)->getRoutingResults();
    var_dump($rr->getDispatcher()->getAllowedMethods($rr->getUri()));
    return $response;
});

$app->run();
php -S localhost:8000 -t public

Output:

array(2) {
    [0]=> string(3) "GET" 
    [1]=> string(3) "GET" 
} 

@l0gicgate l0gicgate added this to the 4.12.0 milestone Jul 23, 2023
@l0gicgate
Copy link
Member

Thank you for this contribution @papparazzo!

@l0gicgate l0gicgate merged commit 3cf4c99 into slimphp:4.x Jul 23, 2023
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

Successfully merging this pull request may close these issues.

2 participants