本文整理汇总了PHP中Psr\Http\Message\StreamInterface::eof方法的典型用法代码示例。如果您正苦于以下问题:PHP StreamInterface::eof方法的具体用法?PHP StreamInterface::eof怎么用?PHP StreamInterface::eof使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\StreamInterface
的用法示例。
在下文中一共展示了StreamInterface::eof方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
/**
* Sends response to output.
* @param IRequest $request
* @param IResponse $response
*/
public function send(IRequest $request, IResponse $response)
{
// Set response headers for the file download
$response->setHeader('Content-Length', $this->stream->getSize());
$response->setHeader('Content-Type', $this->contentType);
$response->setHeader('Content-Disposition', 'attachment; filename="' . $this->name . '";');
while (!$this->stream->eof()) {
echo $this->stream->read(4000000.0);
}
$this->stream->close();
}
示例2: tick
public function tick()
{
do {
$data = $this->psr7Stream->read(1024);
$this->emit('data', [$data, $this]);
} while ($data !== '');
if (!$this->psr7Stream->eof()) {
$this->queueTick();
return;
}
$this->close();
}
示例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;
}
示例4: eof
/**
* {@inheritdoc}
*/
public function eof()
{
if ($this->stream === NULL) {
return true;
}
return $this->stream->eof();
}
示例5: getLine
/**
* Retrieve a single line from the stream.
*
* Retrieves a line from the stream; a line is defined as a sequence of
* characters ending in a CRLF sequence.
*
* @param StreamInterface $stream
* @return string
* @throws UnexpectedValueException if the sequence contains a CR or LF in
* isolation, or ends in a CR.
*/
protected static function getLine(StreamInterface $stream)
{
$line = '';
$crFound = false;
while (!$stream->eof()) {
$char = $stream->read(1);
if ($crFound && $char === self::LF) {
$crFound = false;
break;
}
// CR NOT followed by LF
if ($crFound && $char !== self::LF) {
throw new UnexpectedValueException('Unexpected carriage return detected');
}
// LF in isolation
if (!$crFound && $char === self::LF) {
throw new UnexpectedValueException('Unexpected line feed detected');
}
// CR found; do not append
if ($char === self::CR) {
$crFound = true;
continue;
}
// Any other character: append
$line .= $char;
}
// CR found at end of stream
if ($crFound) {
throw new UnexpectedValueException("Unexpected end of headers");
}
return $line;
}
示例6: 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');
}
}
}
示例7: 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));
}
}
示例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());
}
示例9: 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);
}
示例10: wrapBodyStream
/**
* @param StreamInterface $stream
* @return StreamInterface
*/
private static function wrapBodyStream(StreamInterface $stream)
{
$eofStream = false;
$methods = ['close' => function () use($stream, &$eofStream) {
$stream->close();
$eofStream = true;
}, 'eof' => function () use($stream, &$eofStream) {
return $eofStream || $stream->eof();
}];
//\GuzzleHttp\Stream\FnStream::decorate($stream, $methods);
return \GuzzleHttp\Psr7\FnStream::decorate($stream, $methods);
}
示例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);
}
示例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);
}
示例13: eof
/**
* {@inheritdoc}
*/
public function eof()
{
return $this->decoratedStream->eof();
}
示例14: stream_eof
public function stream_eof()
{
return $this->stream->eof();
}
示例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);
}
}