function SessionStreamWrapper::stream_read

Same name in other branches
  1. 8.x-1.x stream_wrapper_example/src/StreamWrapper/SessionStreamWrapper.php \Drupal\stream_wrapper_example\StreamWrapper\SessionStreamWrapper::stream_read()
  2. 4.0.x modules/stream_wrapper_example/src/StreamWrapper/SessionStreamWrapper.php \Drupal\stream_wrapper_example\StreamWrapper\SessionStreamWrapper::stream_read()

Overrides PhpStreamWrapperInterface::stream_read

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