You are here

public static function StreamWrapper::getResource in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/guzzlehttp/psr7/src/StreamWrapper.php \GuzzleHttp\Psr7\StreamWrapper::getResource()

Returns a resource representing the stream.

Parameters

StreamInterface $stream The stream to get a resource for:

Return value

resource

Throws

\InvalidArgumentException if stream is not readable or writable

4 calls to StreamWrapper::getResource()
InflateStream::__construct in vendor/guzzlehttp/psr7/src/InflateStream.php
StreamWrapperTest::testCanOpenReadonlyStream in vendor/guzzlehttp/psr7/tests/StreamWrapperTest.php
StreamWrapperTest::testResource in vendor/guzzlehttp/psr7/tests/StreamWrapperTest.php
StreamWrapperTest::testValidatesStream in vendor/guzzlehttp/psr7/tests/StreamWrapperTest.php
@expectedException \InvalidArgumentException

File

vendor/guzzlehttp/psr7/src/StreamWrapper.php, line 28

Class

StreamWrapper
Converts Guzzle streams into PHP stream resources.

Namespace

GuzzleHttp\Psr7

Code

public static function getResource(StreamInterface $stream) {
  self::register();
  if ($stream
    ->isReadable()) {
    $mode = $stream
      ->isWritable() ? 'r+' : 'r';
  }
  elseif ($stream
    ->isWritable()) {
    $mode = 'w';
  }
  else {
    throw new \InvalidArgumentException('The stream must be readable, ' . 'writable, or both.');
  }
  return fopen('guzzle://stream', $mode, null, stream_context_create([
    'guzzle' => [
      'stream' => $stream,
    ],
  ]));
}