Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
"league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (^1.0).",
"league/flysystem-cached-adapter": "Required to use the Flysystem cache (^1.0).",
"league/flysystem-sftp": "Required to use the Flysystem SFTP driver (^1.0).",
"psr/http-message": "Required to allow Storage::put to accept a StreamInterface (^1.0)",
"moontoast/math": "Required to use ordered UUIDs (^1.1).",
"pda/pheanstalk": "Required to use the beanstalk queue driver (^4.0).",
"pusher/pusher-php-server": "Required to use the Pusher broadcast driver (^4.0).",
Expand Down
5 changes: 5 additions & 0 deletions src/Illuminate/Filesystem/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use League\Flysystem\FileNotFoundException;
use League\Flysystem\FilesystemInterface;
use PHPUnit\Framework\Assert as PHPUnit;
use Psr\Http\Message\StreamInterface;
use RuntimeException;
use Symfony\Component\HttpFoundation\StreamedResponse;

Expand Down Expand Up @@ -203,6 +204,10 @@ public function put($path, $contents, $options = [])
return $this->putFile($path, $contents, $options);
}

if ($contents instanceof StreamInterface) {
return $this->driver->putStream($path, $contents->detach(), $options);
}

return is_resource($contents)
? $this->driver->putStream($path, $contents, $options)
: $this->driver->put($path, $contents, $options);
Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Filesystem/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"league/flysystem": "Required to use the Flysystem local and FTP drivers (^1.0).",
"league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (^1.0).",
"league/flysystem-cached-adapter": "Required to use the Flysystem cache (^1.0).",
"league/flysystem-sftp": "Required to use the Flysystem SFTP driver (^1.0)."
"league/flysystem-sftp": "Required to use the Flysystem SFTP driver (^1.0).",
"psr/http-message": "Required to allow Storage::put to accept a StreamInterface (^1.0)"
},
"config": {
"sort-packages": true
Expand Down
16 changes: 16 additions & 0 deletions tests/Filesystem/FilesystemAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace Illuminate\Tests\Filesystem;

use GuzzleHttp\Psr7\Stream;
use Illuminate\Contracts\Filesystem\FileExistsException;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Filesystem\FilesystemAdapter;
use InvalidArgumentException;
use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\StreamedResponse;

Expand All @@ -26,6 +28,7 @@ protected function tearDown(): void
{
$filesystem = new Filesystem(new Local(dirname($this->tempDir)));
$filesystem->deleteDir(basename($this->tempDir));
m::close();
}

public function testResponse()
Expand Down Expand Up @@ -218,4 +221,17 @@ public function testStreamInvalidResourceThrows()
$filesystemAdapter = new FilesystemAdapter($this->filesystem);
$filesystemAdapter->writeStream('file.txt', 'foo bar');
}

public function testPutWithStreamInterface()
{
file_put_contents($this->tempDir.'/foo.txt', 'some-data');
$spy = m::spy($this->filesystem);

$filesystemAdapter = new FilesystemAdapter($spy);
$stream = new Stream(fopen($this->tempDir.'/foo.txt', 'r'));
$filesystemAdapter->put('bar.txt', $stream);

$spy->shouldHaveReceived('putStream');
$this->assertEquals('some-data', $filesystemAdapter->get('bar.txt'));
}
}