-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[RateLimiter] [WIP] add attribute for controllers methods #59920
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
base: 7.3
Are you sure you want to change the base?
[RateLimiter] [WIP] add attribute for controllers methods #59920
Conversation
RazielRodrigues
commented
Mar 5, 2025
•
edited by kbond
Loading
edited by kbond
Q | A |
---|---|
Branch? | 7.3 |
Bug fix? | no |
New feature? | yes |
Deprecations? | no |
Issues | Fix #52518 |
License | MIT |
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
This comment was marked as resolved.
This comment was marked as resolved.
Hello, first of all thank you for your interest in contributing to Symfony! It seems the PR is incomplete. The new attribute is indeed created, but it lacks the mechanism to register it and actually rate limit methods, right? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @RazielRodrigues, thanks for getting this started!
This will work very similar to IsGranted
and IsGrantedAttributeListener
so check out the code around these.
* @author Raziel Rodrigues <raziel.rodrigues@outlook.pt> | ||
*/ | ||
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)] | ||
final class RateLimit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll need to rename this file to match the class name: RateLimit.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
*/ | ||
public function __construct( | ||
public string $limiter, | ||
public array $methods |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public array $methods | |
public array $methods = [], |
My thinking is: []
=== all methods (the default)
* @param string $limiter The name of the limiter to use | ||
* @param array $methods Methods to apply the rate limit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @param string $limiter The name of the limiter to use | |
* @param array $methods Methods to apply the rate limit | |
* @param string $limiter The configured limiter name | |
* @param string[] $methods Request methods to apply the rate limit (`[]` for all) |
namespace Symfony\Component\RateLimiter\Attribute; | ||
|
||
/** | ||
* Add the hability to rate limit a method from a controller |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Add the hability to rate limit a method from a controller | |
* Rate limit the controller. |
Question: should the #[RateLimit] attribute point to an implementation of |
I'd actually forgotten about #[RateLimit('my_limiter', key: 'url~method~request.getClientIp()~user?.getUsername()') But now, remembering the |
Thanks for all the comments guys, I will work on this MR this week, I was a bit busy but now I am totally free to work on this merge request, ASAP I will commit the changes |
Hi do you know how can I test the stuff I have done? Because I implemented the event and so on but now I need to test it and I don't know how |