public function vfsStreamFile::lock in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/mikey179/vfsStream/src/main/php/org/bovigo/vfs/vfsStreamFile.php \org\bovigo\vfs\vfsStreamFile::lock()
locks file for
@since 0.10.0
Parameters
resource|vfsStreamWrapper $resource:
int $operation:
Return value
bool
See also
https://github.com/mikey179/vfsStream/issues/6
https://github.com/mikey179/vfsStream/issues/40
File
- vendor/mikey179/ vfsStream/ src/ main/ php/ org/ bovigo/ vfs/ vfsStreamFile.php, line 268 
Class
- vfsStreamFile
- File container.
Namespace
org\bovigo\vfsCode
public function lock($resource, $operation) {
  if ((LOCK_NB & $operation) == LOCK_NB) {
    $operation = $operation - LOCK_NB;
  }
  // call to lock file on the same file handler firstly releases the lock
  $this
    ->unlock($resource);
  if (LOCK_EX === $operation) {
    if ($this
      ->isLocked()) {
      return false;
    }
    $this
      ->setExclusiveLock($resource);
  }
  elseif (LOCK_SH === $operation) {
    if ($this
      ->hasExclusiveLock()) {
      return false;
    }
    $this
      ->addSharedLock($resource);
  }
  return true;
}