當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。