function SessionStreamWrapper::stream_open

Same name and namespace in other branches
  1. 4.0.x modules/stream_wrapper_example/src/StreamWrapper/SessionStreamWrapper.php \Drupal\stream_wrapper_example\StreamWrapper\SessionStreamWrapper::stream_open()

Opens a stream, as for fopen(), file_get_contents(), file_put_contents().

Parameters

string $uri: A string containing the URI to the file to open.

string $mode: The file mode ("r", "wb" etc.).

int $options: A bit mask of STREAM_USE_PATH and STREAM_REPORT_ERRORS.

string &$opened_path: A string containing the path actually opened.

Return value

bool Returns TRUE if file was opened successfully. (Always returns TRUE).

Overrides PhpStreamWrapperInterface::stream_open

See also

http://php.net/manual/en/streamwrapper.stream-open.php

File

modules/stream_wrapper_example/src/StreamWrapper/SessionStreamWrapper.php, line 268

Class

SessionStreamWrapper
Example stream wrapper class to handle session:// streams.

Namespace

Drupal\stream_wrapper_example\StreamWrapper

Code

public function stream_open($uri, $mode, $options, &$opened_path) {
  // @codingStandardsIgnoreEnd
  $this->uri = $uri;
  $path = $this->getLocalPath($uri);
  // We will support two modes only, 'r' and 'w'.  If the key is 'r',
  // check to make sure the file is there.
  if (stristr($mode, 'r') !== FALSE) {
    if (!$this->sessionHelper
      ->checkPath($path)) {
      return FALSE;
    }
    else {
      $buffer = $this->sessionHelper
        ->getPath($path);
      if (!is_string($buffer)) {
        return FALSE;
      }
      $this->sessionContent = $buffer;
    }
    $this->streamMode = 'r';
  }
  else {
    $this->sessionContent = '';
    $this->streamMode = 'w';
  }
  // Reset the stream pointer since this is an open.
  $this->streamPointer = 0;
  return TRUE;
}