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] Flysystem v3 support #40411

Merged
merged 2 commits into from
Jan 14, 2022
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
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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).",
Expand Down
64 changes: 54 additions & 10 deletions src/Illuminate/Filesystem/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)) {
Expand All @@ -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}]."
);
}
}
Expand All @@ -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
Expand All @@ -141,22 +141,22 @@ 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}]."
);
}

return $this;
}

/**
* 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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

/**
Expand All @@ -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.
*
Expand Down Expand Up @@ -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)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I adjusted these because these methods are specifically for files.

return $this->put($path, $data.$separator.$this->get($path));
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/Illuminate/Filesystem/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)."
Expand Down
15 changes: 15 additions & 0 deletions tests/Filesystem/FilesystemAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down