You are here

public function SessionStreamWrapper::stream_open in Examples for Developers 8

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

Return value

bool

Overrides PhpStreamWrapperInterface::stream_open

File

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;
}