self::
configureOptions($options);
$this->config =
$options->
resolve($config);
} public function create(string
$key = null
): LimiterInterface
{ $id =
$this->config
['id'
].'-'.
$key;
$lock =
$this->lockFactory?->
createLock($id);
return match ($this->config
['policy'
]) { 'token_bucket' =>
new TokenBucketLimiter($id,
$this->config
['limit'
],
$this->config
['rate'
],
$this->storage,
$lock),
'fixed_window' =>
new FixedWindowLimiter($id,
$this->config
['limit'
],
$this->config
['interval'
],
$this->storage,
$lock),
'sliding_window' =>
new SlidingWindowLimiter($id,
$this->config
['limit'
],
$this->config
['interval'
],
$this->storage,
$lock),
'no_limit' =>
new NoLimiter(),
default =>
throw new \
LogicException(sprintf('Limiter policy "%s" does not exists, it must be either "token_bucket", "sliding_window", "fixed_window" or "no_limit".',
$this->config
['policy'
])),
};
} protected static function configureOptions(OptionsResolver
$options): void
{ $intervalNormalizer =
static function DOptions
$options, string
$interval): \DateInterval
{ try {