MediaWiki REL1_35
ScopedLock.php
Go to the documentation of this file.
1<?php
35 protected $manager;
36
38 protected $status;
39
41 protected $pathsByType;
42
48 protected function __construct(
50 ) {
51 $this->manager = $manager;
52 $this->pathsByType = $pathsByType;
53 $this->status = $status;
54 }
55
70 public static function factory(
71 LockManager $manager, array $paths, $type, StatusValue $status, $timeout = 0
72 ) {
73 $pathsByType = is_int( $type ) ? [ $type => $paths ] : $paths;
74 $lockStatus = $manager->lockByType( $pathsByType, $timeout );
75 $status->merge( $lockStatus );
76 if ( $lockStatus->isOK() ) {
77 return new self( $manager, $pathsByType, $status );
78 }
79
80 return null;
81 }
82
91 public static function release( ScopedLock &$lock = null ) {
92 $lock = null;
93 }
94
98 public function __destruct() {
99 $wasOk = $this->status->isOK();
100 $this->status->merge( $this->manager->unlockByType( $this->pathsByType ) );
101 if ( $wasOk ) {
102 // Make sure StatusValue is OK, despite any unlockFiles() fatals
103 $this->status->setResult( true, $this->status->value );
104 }
105 }
106}
Class for handling resource locking.
lockByType(array $pathsByType, $timeout=0)
Lock the resources at the given abstract paths.
Self-releasing locks.
static factory(LockManager $manager, array $paths, $type, StatusValue $status, $timeout=0)
Get a ScopedLock object representing a lock on resource paths.
StatusValue $status
__destruct()
Release the locks when this goes out of scope.
array $pathsByType
Map of lock types to resource paths.
static release(ScopedLock &$lock=null)
Release a scoped lock and set any errors in the attatched StatusValue object.
LockManager $manager
__construct(LockManager $manager, array $pathsByType, StatusValue $status)
Generic operation result class Has warning/error list, boolean status and arbitrary value.
merge( $other, $overwriteValue=false)
Merge another status object into this one.