manager = $manager; $this->paths = $paths; $this->status = $status; $this->type = $type; } /** * Get a ScopedLock object representing a lock on resource paths. * Any locks are released once this object goes out of scope. * The status object is updated with any errors or warnings. * * @param $manager LockManager * @param $paths Array List of storage paths * @param $type integer LockManager::LOCK_* constant * @param $status Status * @return ScopedLock|null Returns null on failure */ public static function factory( LockManager $manager, array $paths, $type, Status $status ) { $lockStatus = $manager->lock( $paths, $type ); $status->merge( $lockStatus ); if ( $lockStatus->isOK() ) { return new self( $manager, $paths, $type, $status ); } return null; } function __destruct() { $wasOk = $this->status->isOK(); $this->status->merge( $this->manager->unlock( $this->paths, $this->type ) ); if ( $wasOk ) { // Make sure status is OK, despite any unlockFiles() fatals $this->status->setResult( true, $this->status->value ); } } }