Skip to content

Commit 9bb3628

Browse files
Gman98ishtaylorotwell
authored andcommitted
[6.x] Allow Storage::put to accept a Psr StreamInterface (#30179)
* Allow Storage::put to accept a Psr StreamInterface Addresses: laravel/ideas#1252 * Moved psr/http-message to a suggested dependency * Fixed error in filesystem composer.json
1 parent bf9ad9d commit 9bb3628

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

FilesystemAdapter.php

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use League\Flysystem\FileNotFoundException;
2121
use League\Flysystem\FilesystemInterface;
2222
use PHPUnit\Framework\Assert as PHPUnit;
23+
use Psr\Http\Message\StreamInterface;
2324
use RuntimeException;
2425
use Symfony\Component\HttpFoundation\StreamedResponse;
2526

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

207+
if ($contents instanceof StreamInterface) {
208+
return $this->driver->putStream($path, $contents->detach(), $options);
209+
}
210+
206211
return is_resource($contents)
207212
? $this->driver->putStream($path, $contents, $options)
208213
: $this->driver->put($path, $contents, $options);

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"league/flysystem": "Required to use the Flysystem local and FTP drivers (^1.0).",
3434
"league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (^1.0).",
3535
"league/flysystem-cached-adapter": "Required to use the Flysystem cache (^1.0).",
36-
"league/flysystem-sftp": "Required to use the Flysystem SFTP driver (^1.0)."
36+
"league/flysystem-sftp": "Required to use the Flysystem SFTP driver (^1.0).",
37+
"psr/http-message": "Required to allow Storage::put to accept a StreamInterface (^1.0)"
3738
},
3839
"config": {
3940
"sort-packages": true

0 commit comments

Comments
 (0)