MediaWiki  REL1_22
ScopedLock.php
Go to the documentation of this file.
00001 <?php
00034 class ScopedLock {
00036     protected $manager;
00038     protected $status;
00040     protected $pathsByType;
00041 
00047     protected function __construct( LockManager $manager, array $pathsByType, Status $status ) {
00048         $this->manager = $manager;
00049         $this->pathsByType = $pathsByType;
00050         $this->status = $status;
00051     }
00052 
00068     public static function factory(
00069         LockManager $manager, array $paths, $type, Status $status, $timeout = 0
00070     ) {
00071         $pathsByType = is_integer( $type ) ? array( $type => $paths ) : $paths;
00072         $lockStatus = $manager->lockByType( $pathsByType, $timeout );
00073         $status->merge( $lockStatus );
00074         if ( $lockStatus->isOK() ) {
00075             return new self( $manager, $pathsByType, $status );
00076         }
00077         return null;
00078     }
00079 
00089     public static function release( ScopedLock &$lock = null ) {
00090         $lock = null;
00091     }
00092 
00096     function __destruct() {
00097         $wasOk = $this->status->isOK();
00098         $this->status->merge( $this->manager->unlockByType( $this->pathsByType ) );
00099         if ( $wasOk ) {
00100             // Make sure status is OK, despite any unlockFiles() fatals
00101             $this->status->setResult( true, $this->status->value );
00102         }
00103     }
00104 }