class Lock implements LockInterface, LoggerAwareInterface

Lock is the default implementation of the LockInterface.

Traits

LoggerAwareTrait

Methods

__construct(Key $key, StoreInterface $store, float $ttl = null, bool $autoRelease = true)

No description

__destruct()

Automatically releases the underlying lock when the object is destructed.

bool
acquire(bool $blocking = false)

Acquires the lock. If the lock is acquired by someone else, the parameter blocking determines whether or not the call should block until the release of the lock.

refresh($ttl = null)

Increase the duration of an acquired lock.

bool
isAcquired()

Returns whether or not the lock is acquired.

release()

Release the lock.

bool
isExpired()

No description

float|null
getRemainingLifetime()

Returns the remaining lifetime.

Details

at line 44
__construct(Key $key, StoreInterface $store, float $ttl = null, bool $autoRelease = true)

Parameters

Key $key Resource to lock
StoreInterface $store Store used to handle lock persistence
float $ttl Maximum expected lock duration in seconds
bool $autoRelease Whether to automatically release the lock or not when the lock instance is destroyed

at line 57
__destruct()

Automatically releases the underlying lock when the object is destructed.

at line 69
bool acquire(bool $blocking = false)

Acquires the lock. If the lock is acquired by someone else, the parameter blocking determines whether or not the call should block until the release of the lock.

Parameters

bool $blocking Whether or not the Lock should wait for the release of someone else

Return Value

bool whether or not the lock had been acquired

Exceptions

LockConflictedException If the lock is acquired by someone else in blocking mode
LockAcquiringException If the lock can not be acquired

at line 108
refresh($ttl = null)

Increase the duration of an acquired lock.

Parameters

$ttl

Exceptions

LockConflictedException If the lock is acquired by someone else
LockAcquiringException If the lock can not be refreshed

at line 140
bool isAcquired()

Returns whether or not the lock is acquired.

Return Value

bool

at line 148
release()

Release the lock.

Exceptions

LockReleasingException If the lock can not be released

at line 162
bool isExpired()

Return Value

bool

at line 170
float|null getRemainingLifetime()

Returns the remaining lifetime.

Return Value

float|null Remaining lifetime in seconds. Null when the lock won't expire.