DurationLimiterBuilder
in package
Uses
InteractsWithTime
Table of Contents
- $connection : Connection
- The Redis connection.
- $decay : int
- The amount of time the lock window is maintained.
- $maxLocks : int
- The maximum number of locks that can obtained per time window.
- $name : string
- The name of the lock.
- $timeout : int
- The amount of time to block until a lock is available.
- __construct() : void
- Create a new builder instance.
- allow() : $this
- Set the maximum number of locks that can obtained per time window.
- block() : $this
- Set the amount of time to block until a lock is available.
- every() : $this
- Set the amount of time the lock window is maintained.
- then() : mixed
- Execute the given callback if a lock is obtained, otherwise call the failure callback.
- availableAt() : int
- Get the "available at" UNIX timestamp.
- currentTime() : int
- Get the current system time as a UNIX timestamp.
- parseDateInterval() : DateTimeInterface|int
- If the given value is an interval, convert it to a DateTime instance.
- secondsUntil() : int
- Get the number of seconds until the given DateTime.
Properties
$connection
The Redis connection.
public
Connection
$connection
$decay
The amount of time the lock window is maintained.
public
int
$decay
$maxLocks
The maximum number of locks that can obtained per time window.
public
int
$maxLocks
$name
The name of the lock.
public
string
$name
$timeout
The amount of time to block until a lock is available.
public
int
$timeout
= 3
Methods
__construct()
Create a new builder instance.
public
__construct(Connection $connection, string $name) : void
Parameters
- $connection : Connection
- $name : string
Return values
void —allow()
Set the maximum number of locks that can obtained per time window.
public
allow(int $maxLocks) : $this
Parameters
- $maxLocks : int
Return values
$this —block()
Set the amount of time to block until a lock is available.
public
block(int $timeout) : $this
Parameters
- $timeout : int
Return values
$this —every()
Set the amount of time the lock window is maintained.
public
every(int $decay) : $this
Parameters
- $decay : int
Return values
$this —then()
Execute the given callback if a lock is obtained, otherwise call the failure callback.
public
then(callable $callback[, callable|null $failure = null ]) : mixed
Parameters
- $callback : callable
- $failure : callable|null = null
Tags
Return values
mixed —availableAt()
Get the "available at" UNIX timestamp.
protected
availableAt(DateTimeInterface|DateInterval|int $delay) : int
Parameters
- $delay : DateTimeInterface|DateInterval|int
Return values
int —currentTime()
Get the current system time as a UNIX timestamp.
protected
currentTime() : int
Return values
int —parseDateInterval()
If the given value is an interval, convert it to a DateTime instance.
protected
parseDateInterval(DateTimeInterface|DateInterval|int $delay) : DateTimeInterface|int
Parameters
- $delay : DateTimeInterface|DateInterval|int
Return values
DateTimeInterface|int —secondsUntil()
Get the number of seconds until the given DateTime.
protected
secondsUntil(DateTimeInterface|DateInterval|int $delay) : int
Parameters
- $delay : DateTimeInterface|DateInterval|int