NoLock example

private readonly ?LockFactory $lockFactory = null
    ) {
    }

    public function create(?string $key = null): LimiterInterface
    {
        if ($this->config['enabled'] === false) {
            return new NoLimiter();
        }

        $id = $this->config['id'] . '-' . (string) $key;
        $lock = $this->lockFactory ? $this->lockFactory->createLock($id) : new NoLock();

        if (isset($this->config['reset']) && !($this->config['reset'] instanceof \DateInterval)) {
            $this->config['reset'] = (new \DateTimeImmutable())->diff(new \DateTimeImmutable('+' . $this->config['reset']));
        }

        if ($this->config['policy'] === 'time_backoff' && isset($this->config['limits']) && isset($this->config['reset'])) {
            /** @var list<TimeBackoffLimit> $limits */
            $limits = $this->config['limits'];

            \assert($this->config['reset'] instanceof \DateInterval);

            
private readonly int $reset;

    /** * @param list<TimeBackoffLimit> $limits */
    public function __construct(
        string $id,
        private readonly array $limits,
        \DateInterval $reset,
        StorageInterface $storage,
        LockInterface|null $lock = new NoLock()
    ) {
        $this->id = $id;
        $this->reset = TimeUtil::dateIntervalToSeconds($reset);
        $this->storage = $storage;
        $this->lock = $lock;
    }

    public function reserve(int $tokens = 1, ?float $maxTime = null): Reservation
    {
        throw new ReserveNotSupportedException(self::class);
    }

    
Home | Imprint | This part of the site doesn't use cookies.