本文整理汇总了PHP中Psr\Http\Message\StreamInterface::isReadable方法的典型用法代码示例。如果您正苦于以下问题:PHP StreamInterface::isReadable方法的具体用法?PHP StreamInterface::isReadable怎么用?PHP StreamInterface::isReadable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\StreamInterface
的用法示例。
在下文中一共展示了StreamInterface::isReadable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Decorate the given input stream.
*
* @param StreamInterface $stream
*
* @throws \InvalidArgumentException When the given stream is not readable.
*/
public function __construct(StreamInterface $stream)
{
if (!$stream->isReadable()) {
throw new \InvalidArgumentException(sprintf('Decorated stream must be readable, given %s', get_class($stream)));
}
$this->stream = $stream;
}
示例2: appendStream
/**
* Append another input stream.
*
* @param StreamInterface $stream
*
* @throws \InvalidArgumentException When the given stream is not readable.
*/
public function appendStream(StreamInterface $stream)
{
if (!$stream->isReadable()) {
throw new \InvalidArgumentException('Appended input stream must be readable');
}
$this->streams[] = $stream;
}
示例3: __construct
public function __construct($filename, StreamInterface $stream, $mediaType = NULL)
{
if (!$stream->isReadable()) {
throw new \InvalidArgumentException(sprintf('Input stream of file "%s" must be readable'));
}
$this->fileName = new UnicodeString($filename);
$this->stream = $stream;
$this->mediaType = $mediaType === NULL ? Filesystem::guessMimeTypeFromFilename($this->fileName) : new MediaType($mediaType);
}
示例4: add
/**
* Append stream to stack.
*
* @param StreamInterface $stream
* @return self
*/
public function add(StreamInterface $stream)
{
if (!$stream->isReadable()) {
throw new \InvalidArgumentException('Each stream must be readable');
}
$this->seekable = $stream->isSeekable() && $this->seekable;
$this->streams[] = $stream;
return $this;
}
示例5: fromStream
/**
* Parse a response from a stream.
*
* @param StreamInterface $stream
* @return ResponseInterface
* @throws InvalidArgumentException when the stream is not readable.
* @throws UnexpectedValueException when errors occur parsing the message.
*/
public static function fromStream(StreamInterface $stream)
{
if (!$stream->isReadable() || !$stream->isSeekable()) {
throw new InvalidArgumentException('Message stream must be both readable and seekable');
}
$stream->rewind();
list($version, $status, $reasonPhrase) = self::getStatusLine($stream);
list($headers, $body) = self::splitStream($stream);
return (new Response($body, $status, $headers))->withProtocolVersion($version)->withStatus((int) $status, $reasonPhrase);
}
示例6: addStream
/**
* Add a stream to the AppendStream
*
* @param StreamInterface $stream Stream to append. Must be readable.
*
* @throws \InvalidArgumentException if the stream is not readable
*/
public function addStream(StreamInterface $stream)
{
if (!$stream->isReadable()) {
throw new \InvalidArgumentException('Each stream must be readable');
}
// The stream is only seekable if all streams are seekable
if (!$stream->isSeekable()) {
$this->seekable = false;
}
$this->streams[] = $stream;
}
示例7: fromStream
/**
* Deserialize a request stream to a request instance.
*
* @param StreamInterface $stream
* @return Request
* @throws UnexpectedValueException when errors occur parsing the message.
*/
public static function fromStream(StreamInterface $stream)
{
if (!$stream->isReadable() || !$stream->isSeekable()) {
throw new InvalidArgumentException('Message stream must be both readable and seekable');
}
$stream->rewind();
list($method, $requestTarget, $version) = self::getRequestLine($stream);
$uri = self::createUriFromRequestTarget($requestTarget);
list($headers, $body) = self::splitStream($stream);
return (new Request($uri, $method, $body, $headers))->withProtocolVersion($version)->withRequestTarget($requestTarget);
}
示例8: getResource
/**
* Returns a resource representing the stream.
*
* @param StreamInterface $stream The stream to get a resource for
*
* @return resource
* @throws \InvalidArgumentException if stream is not readable or writable
*/
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]]));
}
示例9: toString
/**
* Converts an stream into an string and returns the result. The position of
* the pointer will not change if the stream is seekable. Note this copies
* the complete content of the stream into the memory
*
* @param \Psr\Http\Message\StreamInterface $stream
* @return string
*/
public static function toString(StreamInterface $stream)
{
if (!$stream->isReadable()) {
return '';
}
if ($stream->isSeekable()) {
$pos = $stream->tell();
if ($pos > 0) {
$stream->seek(0);
}
$content = $stream->getContents();
$stream->seek($pos);
} else {
$content = $stream->getContents();
}
return $content;
}
示例10: isReadable
/**
* {@inheritdoc}
*/
public function isReadable()
{
return $this->stream->isReadable();
}
示例11: testDetaches
public function testDetaches()
{
$this->b->detach();
$this->assertFalse($this->b->isReadable());
}
示例12: isReadable
/**
* {@inheritdoc}
*/
public function isReadable()
{
return $this->decoratedStream->isReadable();
}
示例13: getResource
/**
* Create StreamInterface associated resource.
*
* @param StreamInterface $stream
* @return resource
* @throws WrapperException
*/
public static function getResource(StreamInterface $stream)
{
$mode = null;
if ($stream->isReadable()) {
$mode = 'r';
}
if ($stream->isWritable()) {
$mode = !empty($mode) ? 'r+' : 'w';
}
if (empty($mode)) {
throw new WrapperException("Stream is not available in read or write modes.");
}
return fopen(self::getUri($stream), $mode);
}
示例14: runMatches
protected function runMatches(StreamInterface $stream)
{
return $stream->isReadable();
}
示例15: writeFileContents
protected function writeFileContents($file, StreamInterface $stream)
{
if (!$stream->isReadable()) {
throw new \InvalidArgumentException('Resource content stream must be readable');
}
$fp = Filesystem::openWriteStream($file, 'wb', 0755, LOCK_EX);
try {
while (!$stream->eof()) {
fwrite($fp, $stream->read(4096));
}
} finally {
@fclose($fp);
}
}