rate_limiter.yaml
located in <plugin root>/src/Resources/config/
. The root key of the configuration is the name which has to be a unique key. In this example we named it example_route
.enabled
: Enables / Disables the rate limit for the specific route (default value: true).policy
: Possible policies are fixed_window
, sliding_window
, token_bucket
, time_backoff
. For more information check the Symfony documentation.time_backoff
policy, head over to rate limiter guide. Otherwise, check the Symfony documentation for the other keys you need for each policy.RateLimiterCompilerPass
. If you are not very familiar with compiler passes, head over to the Symfony documentation.rate_limiter.yaml
and reassign it with the merged configuration.build()
method of our SwagBasicExample
plugin class. Important here is to use Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION
with a higher priority, otherwise it will be built too late.Shopware\Core\Framework\RateLimiter\RateLimiter
service.ensureAccepted
of the rate limiter which accepts the following arguments:route
: Unique name of the rate limit, we defined in the configuration.key
: Key we want to use to limit the request e.g., the client IP.ensureAccepted
method it counts the request for the key in the defined cache. If the limit has been exceeded, it throws Shopware\Core\Framework\RateLimiter\Exception\RateLimitExceededException
.reset
method as you can see below.