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
Get requestpath with variables #26
Comments
Currently, this feature is no available. Could you please explain why do you need this feature and what's your use case? |
I'm trying to create ratelimit middleware (https://github.com/Luca-Castelnuovo/CubeQuence-framework/blob/master/src/CubeQuence/Middleware/RateLimit.php). And I would like to be able to have multiple limits set for multiple endpoints. For the following example: $router->get('/foo', 'ExampleController@foo', RateLimit::class); // 45 requests / 60 seconds
$router->get('/bar', 'ExampleController@bar', RateLimit::class); // 10 requests / 5 seconds I was planning to achieve this by getting the request path $path = $request->getUri();
$path = strtok($path, '?');
$path = strtok($path, '#'); And then lookup aan associative array $path = Request::path($request);
$this->max_requests = (int) Config::get("ratelimit.{$path}.max_requests") ?: 60;
$this->reset_time = (int) Config::get("ratelimit.{$path}.reset_time") ?: 60; This would work fine if I didn't use URL params. Because if you use the following: $router->get('/fooBar/{uuid}', 'ExampleController@foo', RateLimit::class); // 45 requests / 60 seconds I wouldn't be able to create an config entry for each uuid. $basePath = Request::basePath($request);
$this->max_requests = (int) Config::get("ratelimit.{$basePath}.max_requests") ?: 60;
$this->reset_time = (int) Config::get("ratelimit.{$basePath}.reset_time") ?: 60; I could configure limits for each route. |
Thanks for your suggestion, I'm working on the next major version of PhpRouter, I will consider this feature. |
This feature is added to the last release. Please check: |
Would it be possible to have an
$request->getUri()
alternative that returns the base path.Example:
/example/{var}
with/example/123
$request->getUri()
returns/example/123
How would I get the original base (
/example/{var}
)? Maybe$request->getBase()
?The text was updated successfully, but these errors were encountered: