From 89cb8d735ab99103b284e19ca50e0c443ba9ef1c Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Fri, 14 Jan 2022 10:27:54 +0100 Subject: [PATCH 1/2] constraints --- composer.json | 14 +++++++------- src/Illuminate/Filesystem/composer.json | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index 721729c9ff4d..ba480c911f5d 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "egulias/email-validator": "^3.1", "laravel/serializable-closure": "^1.0", "league/commonmark": "^2.0.2", - "league/flysystem": "^2.3.1", + "league/flysystem": "^3.0", "monolog/monolog": "^2.0", "nesbot/carbon": "^2.53.1", "psr/container": "^1.1.1|^2.0.1", @@ -83,9 +83,9 @@ "doctrine/dbal": "^2.13.3|^3.1.4", "fakerphp/faker": "^1.9.2", "guzzlehttp/guzzle": "^7.2", - "league/flysystem-aws-s3-v3": "^2.0", - "league/flysystem-ftp": "^2.0", - "league/flysystem-sftp-v3": "^2.4", + "league/flysystem-aws-s3-v3": "^3.0", + "league/flysystem-ftp": "^3.0", + "league/flysystem-sftp-v3": "^3.0", "mockery/mockery": "^1.4.4", "orchestra/testbench-core": "^7.0", "pda/pheanstalk": "^4.0", @@ -146,9 +146,9 @@ "fakerphp/faker": "Required to use the eloquent factory builder (^1.9.1).", "guzzlehttp/guzzle": "Required to use the HTTP Client and the ping methods on schedules (^7.2).", "laravel/tinker": "Required to use the tinker console command (^2.0).", - "league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (^2.0).", - "league/flysystem-ftp": "Required to use the Flysystem FTP driver (^2.0).", - "league/flysystem-sftp-v3": "Required to use the Flysystem SFTP driver (^2.4).", + "league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (^3.0).", + "league/flysystem-ftp": "Required to use the Flysystem FTP driver (^3.0).", + "league/flysystem-sftp-v3": "Required to use the Flysystem SFTP driver (^3.0).", "mockery/mockery": "Required to use mocking (^1.4.4).", "nyholm/psr7": "Required to use PSR-7 bridging features (^1.2).", "pda/pheanstalk": "Required to use the beanstalk queue driver (^4.0).", diff --git a/src/Illuminate/Filesystem/composer.json b/src/Illuminate/Filesystem/composer.json index 94b4dc97fb4f..bb1c217dbc0b 100644 --- a/src/Illuminate/Filesystem/composer.json +++ b/src/Illuminate/Filesystem/composer.json @@ -34,10 +34,10 @@ "suggest": { "ext-ftp": "Required to use the Flysystem FTP driver.", "illuminate/http": "Required for handling uploaded files (^7.0).", - "league/flysystem": "Required to use the Flysystem local driver (^2.3.1).", - "league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (^2.0).", - "league/flysystem-ftp": "Required to use the Flysystem FTP driver (^2.0).", - "league/flysystem-sftp-v3": "Required to use the Flysystem SFTP driver (^2.4).", + "league/flysystem": "Required to use the Flysystem local driver (^3.0).", + "league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (^3.0).", + "league/flysystem-ftp": "Required to use the Flysystem FTP driver (^3.0).", + "league/flysystem-sftp-v3": "Required to use the Flysystem SFTP driver (^3.0).", "psr/http-message": "Required to allow Storage::put to accept a StreamInterface (^1.0).", "symfony/filesystem": "Required to enable support for relative symbolic links (^6.0).", "symfony/mime": "Required to enable support for guessing extensions (^6.0)." From 0beb934ed31552f84ded85bbd6207cc7d789dec0 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Fri, 14 Jan 2022 10:47:24 +0100 Subject: [PATCH 2/2] Flysystem v3 support --- .../Filesystem/FilesystemAdapter.php | 64 ++++++++++++++++--- tests/Filesystem/FilesystemAdapterTest.php | 15 +++++ 2 files changed, 69 insertions(+), 10 deletions(-) diff --git a/src/Illuminate/Filesystem/FilesystemAdapter.php b/src/Illuminate/Filesystem/FilesystemAdapter.php index a55a3c66073e..0d0d30424574 100644 --- a/src/Illuminate/Filesystem/FilesystemAdapter.php +++ b/src/Illuminate/Filesystem/FilesystemAdapter.php @@ -96,7 +96,7 @@ public function __construct(FilesystemOperator $driver, FlysystemAdapter $adapte } /** - * Assert that the given file exists. + * Assert that the given file or directory exists. * * @param string|array $path * @param string|null $content @@ -110,7 +110,7 @@ public function assertExists($path, $content = null) foreach ($paths as $path) { PHPUnit::assertTrue( - $this->exists($path), "Unable to find a file at path [{$path}]." + $this->exists($path), "Unable to find a file or directory at path [{$path}]." ); if (! is_null($content)) { @@ -119,7 +119,7 @@ public function assertExists($path, $content = null) PHPUnit::assertSame( $content, $actual, - "File [{$path}] was found, but content [{$actual}] does not match [{$content}]." + "File or directory [{$path}] was found, but content [{$actual}] does not match [{$content}]." ); } } @@ -128,7 +128,7 @@ public function assertExists($path, $content = null) } /** - * Assert that the given file does not exist. + * Assert that the given file or directory does not exist. * * @param string|array $path * @return $this @@ -141,7 +141,7 @@ public function assertMissing($path) foreach ($paths as $path) { PHPUnit::assertFalse( - $this->exists($path), "Found unexpected file at path [{$path}]." + $this->exists($path), "Found unexpected file or directory at path [{$path}]." ); } @@ -149,14 +149,14 @@ public function assertMissing($path) } /** - * Determine if a file exists. + * Determine if a file or directory exists. * * @param string $path * @return bool */ public function exists($path) { - return $this->driver->fileExists($path); + return $this->driver->has($path); } /** @@ -170,6 +170,50 @@ public function missing($path) return ! $this->exists($path); } + /** + * Determine if a file exists. + * + * @param string $path + * @return bool + */ + public function fileExists($path) + { + return $this->driver->fileExists($path); + } + + /** + * Determine if a file is missing. + * + * @param string $path + * @return bool + */ + public function fileMissing($path) + { + return ! $this->fileExists($path); + } + + /** + * Determine if a directory exists. + * + * @param string $path + * @return bool + */ + public function directoryExists($path) + { + return $this->driver->directoryExists($path); + } + + /** + * Determine if a directory is missing. + * + * @param string $path + * @return bool + */ + public function directoryMissing($path) + { + return ! $this->directoryExists($path); + } + /** * Get the full path for the file at the given "short" path. * @@ -378,7 +422,7 @@ public function setVisibility($path, $visibility) */ public function prepend($path, $data, $separator = PHP_EOL) { - if ($this->exists($path)) { + if ($this->fileExists($path)) { return $this->put($path, $data.$separator.$this->get($path)); } @@ -395,7 +439,7 @@ public function prepend($path, $data, $separator = PHP_EOL) */ public function append($path, $data, $separator = PHP_EOL) { - if ($this->exists($path)) { + if ($this->fileExists($path)) { return $this->put($path, $this->get($path).$separator.$data); } @@ -689,7 +733,7 @@ public function directories($directory = null, $recursive = false) } /** - * Get all (recursive) of the directories within a given directory. + * Get all the directories within a given directory (recursive). * * @param string|null $directory * @return array diff --git a/tests/Filesystem/FilesystemAdapterTest.php b/tests/Filesystem/FilesystemAdapterTest.php index ff3f2a9c2762..c6da781e1874 100644 --- a/tests/Filesystem/FilesystemAdapterTest.php +++ b/tests/Filesystem/FilesystemAdapterTest.php @@ -98,12 +98,27 @@ public function testExists() $this->filesystem->write('file.txt', 'Hello World'); $filesystemAdapter = new FilesystemAdapter($this->filesystem, $this->adapter); $this->assertTrue($filesystemAdapter->exists('file.txt')); + $this->assertTrue($filesystemAdapter->fileExists('file.txt')); } public function testMissing() { $filesystemAdapter = new FilesystemAdapter($this->filesystem, $this->adapter); $this->assertTrue($filesystemAdapter->missing('file.txt')); + $this->assertTrue($filesystemAdapter->fileMissing('file.txt')); + } + + public function testDirectoryExists() + { + $this->filesystem->write('/foo/bar/file.txt', 'Hello World'); + $filesystemAdapter = new FilesystemAdapter($this->filesystem, $this->adapter); + $this->assertTrue($filesystemAdapter->directoryExists('/foo/bar')); + } + + public function testDirectoryMissing() + { + $filesystemAdapter = new FilesystemAdapter($this->filesystem, $this->adapter); + $this->assertTrue($filesystemAdapter->directoryMissing('/foo/bar')); } public function testPath()