本文整理汇总了PHP中Psr\Http\Message\StreamInterface::isSeekable方法的典型用法代码示例。如果您正苦于以下问题:PHP StreamInterface::isSeekable方法的具体用法?PHP StreamInterface::isSeekable怎么用?PHP StreamInterface::isSeekable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\StreamInterface
的用法示例。
在下文中一共展示了StreamInterface::isSeekable方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: copy
/**
* Copy stream to another stream.
*
* @param StreamInterface $src Source stream.
* @param StreamInterface $dest Target stream.
*
* @return void
*/
public static function copy(StreamInterface $src, StreamInterface $dest)
{
if ($src->isSeekable()) {
$src->rewind();
}
while (!$src->eof()) {
$dest->write($src->read(4096));
}
}
示例2: 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;
}
示例3: 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);
}
示例4: 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;
}
示例5: 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);
}
示例6: 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;
}
示例7: isSeekable
/**
* {@inheritdoc}
*/
public function isSeekable()
{
return $this->stream->isSeekable();
}
示例8: isSeekable
/**
* {@inheritdoc}
*/
public function isSeekable()
{
return $this->decoratedStream->isSeekable();
}
示例9: outputBody
private function outputBody(StreamInterface $body)
{
if ($this->chunkSize > 0) {
if ($body->isSeekable()) {
$body->rewind();
}
while (!$body->eof()) {
print $body->read($this->chunkSize);
}
} else {
print (string) $body;
}
}
示例10: runMatches
protected function runMatches(StreamInterface $stream)
{
return $stream->isSeekable();
}
示例11: parseCsv
/**
* Parses csv.
*
* @param StreamInterface $body
*
* @return array
*/
protected function parseCsv(StreamInterface $body)
{
if ($body->isSeekable()) {
$body->rewind();
}
$stream = $body->detach();
$data = [];
while (($row = fgetcsv($stream)) !== false) {
$data[] = $row;
}
fclose($stream);
return $data;
}
示例12: testCheckMethods
public function testCheckMethods()
{
$this->assertEquals($this->a->isReadable(), $this->b->isReadable());
$this->assertEquals($this->a->isWritable(), $this->b->isWritable());
$this->assertEquals($this->a->isSeekable(), $this->b->isSeekable());
}