Supported Versions: PHP 5, PHP 7, PHP 8
Reads remainder of a stream into a string
<?php stream_get_contents(resource $stream, ?int $length = null, int $offset = -1): string|false
<?php namespace League\Flysystem\ZipArchive {
function stream_get_contents(...$arguments) {
if ( ! is_mocked('stream_get_contents')) {
return \stream_get_contents(...$arguments);
}
return return_mocked_value('stream_get_contents');
<?php $this->runScenario(function () {
$readStream = $this->adapter()->readStream('path.txt');
$contents = stream_get_contents($readStream);
$this->assertIsResource($readStream);
$this->assertEquals('contents', $contents);
<?php $readStream = $adapter->readStream('path.txt');
$this->assertIsResource($readStream);
$contents = stream_get_contents($readStream);
fclose($readStream);
$this->assertEquals('contents', $contents);
});
<?php fclose($writeStream);
$this->assertIsResource($readStream);
$this->assertEquals('contents', stream_get_contents($readStream));
fclose($readStream);
}
<?php public function read(string $path): string
{
$readStream = $this->readStream($path);
$contents = stream_get_contents($readStream);
fclose($readStream);
return $contents;
<?php public function writeStream(string $path, $contents, Config $config): void
{
$this->write($path, (string) stream_get_contents($contents), $config);
}
public function read(string $path): string
<?php {
$this->adapter()->write(self::PATH, 'contents', new Config());
$contents = $this->adapter()->readStream(self::PATH);
$this->assertEquals('contents', stream_get_contents($contents));
fclose($contents);
}
<?php $adapter->write('path.txt', 'contents', new Config());
$contents = $adapter->readStream('path.txt');
$this->assertIsResource($contents);
$fileContents = stream_get_contents($contents);
fclose($contents);
$this->assertEquals('contents', $fileContents);
}
<?php $this->secondFilesystem->write('location.txt', 'contents');
$handle = $this->mountManager->readStream('second://location.txt');
$contents = stream_get_contents($handle);
fclose($handle);
$this->assertEquals('contents', $contents);
<?php public function writeStream(string $path, $contents, Config $config): void
{
$contents = stream_get_contents($contents);
if ($contents === false) {
throw UnableToWriteFile::atLocation($path, 'Could not get contents of given resource.');