You are here

public function SessionStreamWrapper::stream_write in Examples for Developers 3.x

Same name and namespace in other branches
  1. 8 stream_wrapper_example/src/StreamWrapper/SessionStreamWrapper.php \Drupal\stream_wrapper_example\StreamWrapper\SessionStreamWrapper::stream_write()

Write to stream.

This method is called in response to fwrite(). Remember to update the current position of the stream by number of bytes that were successfully written.

Parameters

string $data: Should be stored into the underlying stream. If there is not enough room in the underlying stream, store as much as possible.

Return value

int Should return the number of bytes that were successfully stored, or 0 if none could be stored.

Overrides PhpStreamWrapperInterface::stream_write

See also

fwrite()

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

File

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

Class

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

Namespace

Drupal\stream_wrapper_example\StreamWrapper

Code

public function stream_write($data) {

  // @codingStandardsIgnoreEnd
  // Sanitize the data in a simple way since we're putting it into the
  // session variable.
  $data = Html::escape($data);
  $this->sessionContent = substr_replace($this->sessionContent, $data, $this->streamPointer);
  $this->streamPointer += strlen($data);
  return strlen($data);
}