MediaWiki master
Wikimedia\LockManager\ScopedLock Class Reference

Self-releasing locks. More...

Collaboration diagram for Wikimedia\LockManager\ScopedLock:

Public Member Functions

 __destruct ()
 Release the locks when this goes out of scope.
 

Static Public Member Functions

static factory (LockManager $manager, array $paths, $type, StatusValue $status, $timeout=0)
 Get a ScopedLock object representing a lock on resource paths.
 
static release (?ScopedLock &$lock=null)
 Release a scoped lock and set any errors in the attached StatusValue object.
 

Protected Member Functions

 __construct (LockManager $manager, array $pathsByType, StatusValue $status)
 

Protected Attributes

LockManager $manager
 
array $pathsByType
 Map of lock types to resource paths.
 
StatusValue $status
 

Detailed Description

Self-releasing locks.

Helper for consumers of LockManager, to create locks that automatically release when an object is destroyed or goes out of scope.

Since
1.19

Definition at line 19 of file ScopedLock.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\LockManager\ScopedLock::__construct ( LockManager $manager,
array $pathsByType,
StatusValue $status )
protected
Parameters
LockManager$manager
array$pathsByTypeMap of lock types to path lists
StatusValue$status

Definition at line 32 of file ScopedLock.php.

References Wikimedia\LockManager\ScopedLock\$manager, Wikimedia\LockManager\ScopedLock\$pathsByType, and Wikimedia\LockManager\ScopedLock\$status.

◆ __destruct()

Wikimedia\LockManager\ScopedLock::__destruct ( )

Release the locks when this goes out of scope.

Definition at line 82 of file ScopedLock.php.

Member Function Documentation

◆ factory()

static Wikimedia\LockManager\ScopedLock::factory ( LockManager $manager,
array $paths,
$type,
StatusValue $status,
$timeout = 0 )
static

Get a ScopedLock object representing a lock on resource paths.

Any locks are released once this object goes out of scope. The StatusValue object is updated with any errors or warnings.

Parameters
LockManager$manager
array$pathsList of storage paths or map of lock types to path lists
int | string$typeLockManager::LOCK_* constant or "mixed" and $paths can be a map of types to paths (since 1.22). Otherwise $type should be an integer and $paths should be a list of paths.
StatusValue$status
int$timeoutTimeout in seconds (0 means non-blocking) (since 1.22)
Returns
ScopedLock|null Returns null on failure

Definition at line 54 of file ScopedLock.php.

References Wikimedia\LockManager\ScopedLock\$manager, Wikimedia\LockManager\ScopedLock\$pathsByType, Wikimedia\LockManager\ScopedLock\$status, Wikimedia\LockManager\LockManager\lockByType(), and StatusValue\merge().

Referenced by Wikimedia\FileBackend\FileBackend\getScopedFileLocks().

◆ release()

static Wikimedia\LockManager\ScopedLock::release ( ?ScopedLock & $lock = null)
static

Release a scoped lock and set any errors in the attached StatusValue object.

This is useful for early release of locks before function scope is destroyed. This is the same as setting the lock object to null.

Parameters
ScopedLock | null&$lock
Since
1.21

Definition at line 75 of file ScopedLock.php.

Member Data Documentation

◆ $manager

LockManager Wikimedia\LockManager\ScopedLock::$manager
protected

◆ $pathsByType

array Wikimedia\LockManager\ScopedLock::$pathsByType
protected

Map of lock types to resource paths.

Definition at line 25 of file ScopedLock.php.

Referenced by Wikimedia\LockManager\ScopedLock\__construct(), and Wikimedia\LockManager\ScopedLock\factory().

◆ $status

StatusValue Wikimedia\LockManager\ScopedLock::$status
protected

The documentation for this class was generated from the following file: