Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[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

Open
wants to merge 5 commits into
base: 7.4
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 1 src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
7.3
---

* Add `rate_limiter` controller attribute
* Add support for assets pre-compression
* Rename `TranslationUpdateCommand` to `TranslationExtractCommand`
* Add JsonStreamer services and configuration
Expand Down
32 changes: 32 additions & 0 deletions 32 src/Symfony/Component/RateLimiter/Attribute/RateLimitAttribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\RateLimiter\Attribute;

/**
* Add the hability to rate limit a method from a controller
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Add the hability to rate limit a method from a controller
* Rate limit the controller.

*
* @see https://symfony.com/doc/current/rate_limiter.html
*
* @author Raziel Rodrigues <raziel.rodrigues@outlook.pt>
*/
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)]
final class RateLimit
Copy link
Member

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

{
/**
* @param string $limiter The name of the limiter to use
* @param array $methods Methods to apply the rate limit
Copy link
Member

@kbond kbond Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @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)

*/
public function __construct(
public string $limiter,
public array $methods
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public array $methods
public array $methods = [],

My thinking is: [] === all methods (the default)

) {}
}
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.