Documentation

Lock
in package
Uses InteractsWithTime

Table of Contents

$name  : string
The name of the lock.
$seconds  : int
The number of seconds the lock should be maintained.
__construct()  : void
Create a new lock instance.
acquire()  : bool
Attempt to acquire the lock.
block()  : bool
Attempt to acquire the lock for the given number of seconds.
get()  : bool
Attempt to acquire the lock.
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

$name

The name of the lock.

protected string $name

$seconds

The number of seconds the lock should be maintained.

protected int $seconds

Methods

__construct()

Create a new lock instance.

public __construct(string $name, int $seconds) : void
Parameters
$name : string
$seconds : int
Return values
void

acquire()

Attempt to acquire the lock.

public abstract acquire() : bool
Return values
bool

block()

Attempt to acquire the lock for the given number of seconds.

public block(int $seconds[, callable|null $callback = null ]) : bool
Parameters
$seconds : int
$callback : callable|null = null
Tags
throws
LockTimeoutException
Return values
bool

get()

Attempt to acquire the lock.

public get([callable|null $callback = null ]) : bool
Parameters
$callback : callable|null = null
Return values
bool

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
Return values
int

Search results