function SessionStreamWrapper::stream_read

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_read()

Support for fread(), file_get_contents() etc.

Parameters

int $count: Maximum number of bytes to be read.

Return value

string The string that was read, or FALSE in case of an error.

Overrides PhpStreamWrapperInterface::stream_read

See also

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

File

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

Class

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

Namespace

Drupal\stream_wrapper_example\StreamWrapper

Code

public function stream_read($count) {
  // @codingStandardsIgnoreEnd
  if (is_string($this->sessionContent)) {
    $remaining_chars = strlen($this->sessionContent) - $this->streamPointer;
    $number_to_read = min($count, $remaining_chars);
    if ($remaining_chars > 0) {
      $buffer = substr($this->sessionContent, $this->streamPointer, $number_to_read);
      $this->streamPointer += $number_to_read;
      return $buffer;
    }
  }
  return FALSE;
}