You are here

public function LocalReadOnlyStream::stream_lock in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/StreamWrapper/LocalReadOnlyStream.php \Drupal\Core\StreamWrapper\LocalReadOnlyStream::stream_lock()

Support for flock().

An exclusive lock attempt will be rejected, as this is a read-only stream wrapper.

Parameters

int $operation: One of the following:

  • LOCK_SH to acquire a shared lock (reader).
  • LOCK_EX to acquire an exclusive lock (writer).
  • LOCK_UN to release a lock (shared or exclusive).
  • LOCK_NB added as a bitmask if you don't want flock() to block while locking (not supported on Windows).

Return value

bool Return FALSE for an exclusive lock (writer), as this is a read-only stream wrapper. Return the result of flock() for other valid operations. Defaults to TRUE if an invalid operation is passed.

Overrides LocalStream::stream_lock

See also

http://php.net/manual/streamwrapper.stream-lock.php

File

core/lib/Drupal/Core/StreamWrapper/LocalReadOnlyStream.php, line 82
Contains \Drupal\Core\StreamWrapper\LocalReadOnlyStream.

Class

LocalReadOnlyStream
Defines a read-only Drupal stream wrapper base class for local files.

Namespace

Drupal\Core\StreamWrapper

Code

public function stream_lock($operation) {

  // Disallow exclusive lock or non-blocking lock requests
  if (in_array($operation, array(
    LOCK_EX,
    LOCK_EX | LOCK_NB,
  ))) {
    trigger_error('stream_lock() exclusive lock operations not supported for read-only stream wrappers', E_USER_WARNING);
    return FALSE;
  }
  if (in_array($operation, array(
    LOCK_SH,
    LOCK_UN,
    LOCK_SH | LOCK_NB,
  ))) {
    return flock($this->handle, $operation);
  }
  return TRUE;
}