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