MediaWiki  REL1_21
ScopedLock.php
Go to the documentation of this file.
00001 <?php
00034 class ScopedLock {
00036         protected $manager;
00038         protected $status;
00040         protected $paths;
00041 
00042         protected $type; // integer lock type
00043 
00050         protected function __construct(
00051                 LockManager $manager, array $paths, $type, Status $status
00052         ) {
00053                 $this->manager = $manager;
00054                 $this->paths = $paths;
00055                 $this->status = $status;
00056                 $this->type = $type;
00057         }
00058 
00070         public static function factory(
00071                 LockManager $manager, array $paths, $type, Status $status
00072         ) {
00073                 $lockStatus = $manager->lock( $paths, $type );
00074                 $status->merge( $lockStatus );
00075                 if ( $lockStatus->isOK() ) {
00076                         return new self( $manager, $paths, $type, $status );
00077                 }
00078                 return null;
00079         }
00080 
00090         public static function release( ScopedLock &$lock = null ) {
00091                 $lock = null;
00092         }
00093 
00094         function __destruct() {
00095                 $wasOk = $this->status->isOK();
00096                 $this->status->merge( $this->manager->unlock( $this->paths, $this->type ) );
00097                 if ( $wasOk ) {
00098                         // Make sure status is OK, despite any unlockFiles() fatals
00099                         $this->status->setResult( true, $this->status->value );
00100                 }
00101         }
00102 }