Skip to content

Commit

Permalink
Allow Storage::put to accept a Psr StreamInterface
Browse files Browse the repository at this point in the history
Remove brackets arround URL php artisan serve (laravel#30168)

To allow opening the development URL in Visual Studio Code with ctrl + click the bracket after the URL needs to be removed.
This patch wil remove the brackets around the url.

add test for sorted middlewares (laravel#30166)

[6.x] Apply limit to database rather than collection (laravel#30148)

* Apply limit to database rather than collection

For HasInDatabase.php

* Fix tests

* Add to SoftDeleted trait as well

* Update HasInDatabase.php

* Update SoftDeletedInDatabase.php

[6.x] Allow to use scoped macro in nested queries (laravel#30127)

* Allow to use scoped macro in nested queries.

* Use newQueryWithoutRelationships
  • Loading branch information
Gman98ish committed Oct 4, 2019
1 parent 88adf85 commit 89ee73c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"opis/closure": "^3.1",
"psr/container": "^1.0",
"psr/simple-cache": "^1.0",
"psr/http-message": "^1.0",
"ramsey/uuid": "^3.7",
"swiftmailer/swiftmailer": "^6.0",
"symfony/console": "^4.3.4",
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
17 changes: 17 additions & 0 deletions tests/Filesystem/FilesystemAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

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 Psr\Http\Message\StreamInterface;
use Symfony\Component\HttpFoundation\StreamedResponse;

class FilesystemAdapterTest extends TestCase
Expand All @@ -26,6 +29,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 +222,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'));
}
}

0 comments on commit 89ee73c

Please sign in to comment.