Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Add conditionable trait to Filesystem adapters #43450

Merged
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
3 changes: 3 additions & 0 deletions src/Illuminate/Filesystem/AwsS3V3Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
namespace Illuminate\Filesystem;

use Aws\S3\S3Client;
use Illuminate\Support\Traits\Conditionable;
use League\Flysystem\AwsS3V3\AwsS3V3Adapter as S3Adapter;
use League\Flysystem\FilesystemOperator;

class AwsS3V3Adapter extends FilesystemAdapter
{
use Conditionable;

/**
* The AWS S3 client.
*
Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use FilesystemIterator;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Support\LazyCollection;
use Illuminate\Support\Traits\Conditionable;
use Illuminate\Support\Traits\Macroable;
use RuntimeException;
use SplFileObject;
Expand All @@ -15,6 +16,7 @@

class Filesystem
{
use Conditionable;
use Macroable;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Filesystem/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Conditionable;
use Illuminate\Support\Traits\Macroable;
use InvalidArgumentException;
use League\Flysystem\FilesystemAdapter as FlysystemAdapter;
Expand Down Expand Up @@ -38,6 +39,7 @@
*/
class FilesystemAdapter implements CloudFilesystemContract
{
use Conditionable;
use Macroable {
__call as macroCall;
}
Expand Down
16 changes: 16 additions & 0 deletions tests/Integration/Filesystem/StorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,20 @@ public function testItCanDeleteViaFilesystemRequiresManualClearStatCacheOnStorag
Storage::disk('public')->assertMissing('StardewTaylor.png');
$this->assertFalse(Storage::disk('public')->exists('StardewTaylor.png'));
}

public function testConditionable()
{
Storage::disk('public')->assertExists('StardewTaylor.png');
$this->assertTrue(Storage::disk('public')->exists('StardewTaylor.png'));

Storage::disk('public')->when(false)->delete('StardewTaylor.png');

Storage::disk('public')->assertExists('StardewTaylor.png');
$this->assertTrue(Storage::disk('public')->exists('StardewTaylor.png'));

Storage::disk('public')->when(true)->delete('StardewTaylor.png');

Storage::disk('public')->assertMissing('StardewTaylor.png');
$this->assertFalse(Storage::disk('public')->exists('StardewTaylor.png'));
}
}