Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:7.4
Are you sure you want to change the base?
[RateLimiter] [WIP] add attribute for controllers methods#59920
Uh oh!
There was an error while loading.Please reload this page.
Conversation
carsonbot commentedMar 5, 2025
Hey! I see that this is your first PR. That is great! Welcome! Symfony has acontribution 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 toIsGranted
andIsGrantedAttributeListener
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 Thename of thelimitertouse | |
* @paramarray$methodsMethodsto apply the rate limit | |
* @param string$limiter Theconfiguredlimitername | |
* @paramstring[]$methodsRequest methodsto 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 ratelimita method from acontroller | |
*Ratelimitthecontroller. |
Question: should the #[RateLimit] attribute point to an implementation of |
kbond commentedMar 6, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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 |
Uh oh!
There was an error while loading.Please reload this page.