MediaWiki
master
Toggle main menu visibility
ScopedLock.php
Go to the documentation of this file.
1
<?php
6
namespace
Wikimedia\LockManager;
7
8
use StatusValue;
9
19
class
ScopedLock
{
21
protected
$manager
;
23
protected
$status
;
25
protected
$pathsByType
;
26
32
protected
function
__construct
(
33
LockManager
$manager
, array
$pathsByType
, StatusValue
$status
34
) {
35
$this->manager =
$manager
;
36
$this->pathsByType =
$pathsByType
;
37
$this->status =
$status
;
38
}
39
54
public
static
function
factory
(
55
LockManager
$manager
, array $paths, $type, StatusValue
$status
, $timeout = 0
56
) {
57
$pathsByType
= is_int( $type ) ? [ $type => $paths ] : $paths;
58
$lockStatus =
$manager
->
lockByType
(
$pathsByType
, $timeout );
59
$status
->
merge
( $lockStatus );
60
if
( $lockStatus->isOK() ) {
61
return
new
self
(
$manager
,
$pathsByType
,
$status
);
62
}
63
64
return
null
;
65
}
66
75
public
static
function
release
( ?
ScopedLock
&$lock =
null
) {
76
$lock =
null
;
77
}
78
82
public
function
__destruct
() {
83
$wasOk = $this->status->isOK();
84
$this->status->merge( $this->manager->unlockByType( $this->pathsByType ) );
85
if
( $wasOk ) {
86
// Make sure StatusValue is OK, despite any unlockFiles() fatals
87
$this->status->setResult(
true
, $this->status->value );
88
}
89
}
90
}
91
92
class_alias( ScopedLock::class,
'ScopedLock'
);
StatusValue\merge
merge( $other, $overwriteValue=false)
Merge another status object into this one.
Definition
StatusValue.php:352
Wikimedia\LockManager\LockManager
Resource locking handling.
Definition
LockManager.php:37
Wikimedia\LockManager\LockManager\lockByType
lockByType(array $pathsByType, $timeout=0)
Lock the resources at the given abstract paths.
Definition
LockManager.php:126
Wikimedia\LockManager\ScopedLock
Self-releasing locks.
Definition
ScopedLock.php:19
Wikimedia\LockManager\ScopedLock\release
static release(?ScopedLock &$lock=null)
Release a scoped lock and set any errors in the attached StatusValue object.
Definition
ScopedLock.php:75
Wikimedia\LockManager\ScopedLock\__destruct
__destruct()
Release the locks when this goes out of scope.
Definition
ScopedLock.php:82
Wikimedia\LockManager\ScopedLock\__construct
__construct(LockManager $manager, array $pathsByType, StatusValue $status)
Definition
ScopedLock.php:32
Wikimedia\LockManager\ScopedLock\$status
StatusValue $status
Definition
ScopedLock.php:23
Wikimedia\LockManager\ScopedLock\$manager
LockManager $manager
Definition
ScopedLock.php:21
Wikimedia\LockManager\ScopedLock\factory
static factory(LockManager $manager, array $paths, $type, StatusValue $status, $timeout=0)
Get a ScopedLock object representing a lock on resource paths.
Definition
ScopedLock.php:54
Wikimedia\LockManager\ScopedLock\$pathsByType
array $pathsByType
Map of lock types to resource paths.
Definition
ScopedLock.php:25
includes
libs
LockManager
ScopedLock.php
Generated on
for MediaWiki by
1.18.0