You are here

public function Stream::write in Zircon Profile 8

Same name in this branch
  1. 8 vendor/zendframework/zend-diactoros/src/Stream.php \Zend\Diactoros\Stream::write()
  2. 8 vendor/guzzlehttp/psr7/src/Stream.php \GuzzleHttp\Psr7\Stream::write()
  3. 8 vendor/symfony/psr-http-message-bridge/Tests/Fixtures/Stream.php \Symfony\Bridge\PsrHttpMessage\Tests\Fixtures\Stream::write()
Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-diactoros/src/Stream.php \Zend\Diactoros\Stream::write()

Write data to the stream.

Parameters

string $string The string that is to be written.:

Return value

int Returns the number of bytes written to the stream.

Throws

\RuntimeException on failure.

Overrides StreamInterface::write

File

vendor/zendframework/zend-diactoros/src/Stream.php, line 204

Class

Stream
Implementation of PSR HTTP streams

Namespace

Zend\Diactoros

Code

public function write($string) {
  if (!$this->resource) {
    throw new RuntimeException('No resource available; cannot write');
  }
  if (!$this
    ->isWritable()) {
    throw new RuntimeException('Stream is not writable');
  }
  $result = fwrite($this->resource, $string);
  if (false === $result) {
    throw new RuntimeException('Error writing to stream');
  }
  return $result;
}