当前位置: 首页>>代码示例>>PHP>>正文


PHP StreamInterface::rewind方法代码示例

本文整理汇总了PHP中Psr\Http\Message\StreamInterface::rewind方法的典型用法代码示例。如果您正苦于以下问题:PHP StreamInterface::rewind方法的具体用法?PHP StreamInterface::rewind怎么用?PHP StreamInterface::rewind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Psr\Http\Message\StreamInterface的用法示例。


在下文中一共展示了StreamInterface::rewind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: stream_open

 /**
  * Open pre-mocked StreamInterface by it's unique uri.
  *
  * @param string $path
  * @param int    $mode
  * @param int    $options
  * @param string &$opened_path
  * @return bool
  */
 public function stream_open($path, $mode, $options, &$opened_path)
 {
     if (!isset(self::$uris[$path])) {
         return false;
     }
     $this->stream = self::$uris[$path];
     $this->mode = $mode;
     $this->stream->rewind();
     return true;
 }
开发者ID:tuneyourserver,项目名称:components,代码行数:19,代码来源:StreamWrapper.php

示例2: __toString

 /**
  * {@inheritdoc}
  */
 public function __toString() : string
 {
     $str = $this->getStartLine();
     foreach ($this->getHeaders() as $name => $values) {
         $str .= sprintf("%s: %s\r\n", $name, implode(', ', $values));
     }
     $str .= "\r\n";
     $this->body->rewind();
     $str .= $this->body->getContents();
     return $str;
 }
开发者ID:axiomphp,项目名称:http-message,代码行数:14,代码来源:AbstractMessage.php

示例3: moveTo

 /**
  * Move the uploaded file to a new location.
  *
  * Use this method as an alternative to move_uploaded_file(). This method is
  * guaranteed to work in both SAPI and non-SAPI environments.
  * Implementations must determine which environment they are in, and use the
  * appropriate method (move_uploaded_file(), rename(), or a stream
  * operation) to perform the operation.
  *
  * $targetPath may be an absolute path, or a relative path. If it is a
  * relative path, resolution should be the same as used by PHP's rename()
  * function.
  *
  * The original file or stream MUST be removed on completion.
  *
  * If this method is called more than once, any subsequent calls MUST raise
  * an exception.
  *
  * When used in an SAPI environment where $_FILES is populated, when writing
  * files via moveTo(), is_uploaded_file() and move_uploaded_file() SHOULD be
  * used to ensure permissions and upload status are verified correctly.
  *
  * If you wish to move to a stream, use getStream(), as SAPI operations
  * cannot guarantee writing to stream destinations.
  *
  * @see http://php.net/is_uploaded_file
  * @see http://php.net/move_uploaded_file
  * @param string $targetPath Path to which to move the uploaded file.
  * @throws \InvalidArgumentException if the $path specified is invalid.
  * @throws \RuntimeException on any error during the move operation, or on the second or subsequent call to the method.
  */
 public function moveTo($targetPath)
 {
     if (!is_string($targetPath) || empty($targetPath)) {
         throw new \InvalidArgumentException('Invalid path while moving an uploaded file.', 1436717307);
     }
     if ($this->moved) {
         throw new \RuntimeException('Cannot move uploaded file, as it was already moved.', 1436717308);
     }
     // Check if the target path is inside the allowed paths of TYPO3, and make it absolute.
     $targetPath = GeneralUtility::getFileAbsFileName($targetPath);
     if (empty($targetPath)) {
         throw new \RuntimeException('Cannot move uploaded file, as it was already moved.', 1436717309);
     }
     if (!empty($this->file) && is_uploaded_file($this->file)) {
         if (GeneralUtility::upload_copy_move($this->file, $targetPath . basename($this->file)) === false) {
             throw new \RuntimeException('An error occurred while moving uploaded file', 1436717310);
         }
     } elseif ($this->stream) {
         $handle = fopen($targetPath, 'wb+');
         if ($handle === false) {
             throw new \RuntimeException('Unable to write to target path.', 1436717311);
         }
         $this->stream->rewind();
         while (!$this->stream->eof()) {
             fwrite($handle, $this->stream->read(4096));
         }
         fclose($handle);
     }
     $this->moved = true;
 }
开发者ID:rickymathew,项目名称:TYPO3.CMS,代码行数:61,代码来源:UploadedFile.php

示例4: 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));
     }
 }
开发者ID:kaiwa,项目名称:http,代码行数:17,代码来源:StreamHelper.php

示例5: moveTo

 public function moveTo($targetPath)
 {
     if (!PHP_SAPI || PHP_SAPI == 'cli') {
         $handle = fopen($targetPath, Stream::MODE_READ_REPLACE);
         if ($handle === false) {
             throw new \RuntimeException('Unable to write to: ' . $targetPath);
         }
         $this->stream->rewind();
         while (!$this->stream->eof()) {
             fwrite($handle, $this->stream->read(4096));
         }
         fclose($handle);
     } else {
         if (move_uploaded_file($this->filePath, $targetPath) === false) {
             throw new \RuntimeException('Error moving uploaded file');
         }
     }
 }
开发者ID:packaged,项目名称:http,代码行数:18,代码来源:UploadedFile.php

示例6: body

 /**
  * @param StreamInterface $stream
  */
 protected function body($stream)
 {
     if ($stream instanceof Messages\Stream\Implementation) {
         $stream->rewind();
         $this->fpassthru($stream->resource());
     } else {
         $this->output((string) $stream);
     }
 }
开发者ID:phpixie,项目名称:http,代码行数:12,代码来源:Output.php

示例7: 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);
 }
开发者ID:DenLilleMand,项目名称:christianssite,代码行数:18,代码来源:Serializer.php

示例8: testReadAndWrite

 public function testReadAndWrite()
 {
     $this->assertEquals(0, $this->stream->getSize());
     $this->stream->write("Hello World, And All Developers!");
     $this->assertEquals(32, $this->stream->getSize());
     // size
     $this->assertEquals(32, $this->stream->tell());
     // pointer
     $this->stream->rewind();
     $this->assertEquals(0, $this->stream->tell());
     $this->assertFalse($this->stream->eof());
     $this->assertEquals("Hell", $this->stream->read(4));
     $this->assertEquals("o World, ", $this->stream->read(9));
     $this->assertEquals("And All Developers!", $this->stream->getContents());
     $this->assertTrue($this->stream->eof());
     $this->stream->seek(12);
     $this->assertEquals(6, $this->stream->write('Hum...'));
     $this->assertEquals("ll Developers!", $this->stream->getContents());
     $this->assertEquals("Hello World,Hum...ll Developers!", $this->stream->__toString());
 }
开发者ID:Golpha,项目名称:Http,代码行数:20,代码来源:StreamTestTrait.php

示例9: 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);
 }
开发者ID:zendframework,项目名称:zend-diactoros,代码行数:18,代码来源:Serializer.php

示例10: writeFile

 /**
  * Write internal stream to given path
  *
  * @param string $path
  */
 protected function writeFile($path)
 {
     $handle = fopen($path, Stream::MODE_READ_WRITE_RESET);
     if ($handle === false) {
         throw new \RuntimeException('Unable to write to path: ' . $path);
     }
     $this->stream->rewind();
     while (!$this->stream->eof()) {
         fwrite($handle, $this->stream->read(4096));
     }
     fclose($handle);
 }
开发者ID:ventoviro,项目名称:windwalker-http,代码行数:17,代码来源:UploadedFile.php

示例11: writeFile

 /**
  * Write internal stream to given path
  *
  * @param string $path
  */
 private function writeFile($path)
 {
     $handle = fopen($path, 'wb+');
     if (false === $handle) {
         throw new RuntimeException('Unable to write to designated path');
     }
     $this->stream->rewind();
     while (!$this->stream->eof()) {
         fwrite($handle, $this->stream->read(4096));
     }
     fclose($handle);
 }
开发者ID:phly,项目名称:http,代码行数:17,代码来源:UploadedFile.php

示例12: writeStream

 /**
  * Write the stream to the given path.
  *
  * @param StreamInterface $stream
  * @param string          $path
  */
 protected static function writeStream(StreamInterface $stream, $path)
 {
     $dir = dirname($path);
     if (!is_dir($dir)) {
         mkdir($dir, 0777, true);
     }
     $handle = fopen($path, 'wb+');
     if (false === $handle) {
         throw new RuntimeException('Unable to write to designated path');
     }
     $stream->rewind();
     while (!$stream->eof()) {
         fwrite($handle, $stream->read(4096));
     }
     fclose($handle);
 }
开发者ID:jordiwes,项目名称:psr7-middlewares,代码行数:22,代码来源:SaveResponse.php

示例13: doCreateStream

 /**
  * Creates a stream.
  *
  * @param null|resource|string|\Psr\Http\Message\StreamInterface|null $body The body
  *
  * @return \Psr\Http\Message\StreamInterface The stream
  */
 private function doCreateStream($body)
 {
     if ($body instanceof StreamInterface) {
         $body->rewind();
         return $body;
     }
     if (is_resource($body)) {
         return $this->doCreateStream(new Stream($body));
     }
     $stream = new Stream('php://memory', 'rw');
     if ($body === null) {
         return $stream;
     }
     $stream->write((string) $body);
     return $this->doCreateStream($stream);
 }
开发者ID:phmlabs,项目名称:smoke,代码行数:23,代码来源:MessageFactory.php

示例14: writeResponse

 /**
  * Write a response to the connection as FCGI_STDOUT records.
  *
  * @param int             $requestId  The request id to write to
  * @param string          $headerData The header data to write (including terminating CRLFCRLF)
  * @param StreamInterface $stream     The stream to write
  */
 private function writeResponse($requestId, $headerData, StreamInterface $stream)
 {
     $data = $headerData;
     $eof = false;
     $stream->rewind();
     do {
         $dataLength = strlen($data);
         if ($dataLength < 65535 && !$eof && !($eof = $stream->eof())) {
             $readLength = 65535 - $dataLength;
             $data .= $stream->read($readLength);
             $dataLength = strlen($data);
         }
         $writeSize = min($dataLength, 65535);
         $writeData = substr($data, 0, $writeSize);
         $data = substr($data, $writeSize);
         $this->writeRecord($requestId, DaemonInterface::FCGI_STDOUT, $writeData);
     } while ($writeSize === 65535);
     $this->writeRecord($requestId, DaemonInterface::FCGI_STDOUT);
 }
开发者ID:sojimaxi,项目名称:FastCGIDaemon,代码行数:26,代码来源:ConnectionHandler.php

示例15: 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;
     }
 }
开发者ID:pjdietz,项目名称:wellrested,代码行数:13,代码来源:Transmitter.php


注:本文中的Psr\Http\Message\StreamInterface::rewind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。