From 894b4923742ad42b67a823d6672214ad7d579b7d Mon Sep 17 00:00:00 2001 From: Jesper Noordsij Date: Sat, 18 Nov 2023 14:56:34 +0100 Subject: [PATCH 1/2] Add Config const for retain_visibility option --- src/AsyncAwsS3/AsyncAwsS3Adapter.php | 2 +- src/AwsS3V3/AwsS3V3Adapter.php | 2 +- src/Config.php | 1 + src/Filesystem.php | 2 +- src/Ftp/FtpAdapter.php | 2 +- src/GoogleCloudStorage/GoogleCloudStorageAdapter.php | 2 +- src/Local/LocalFilesystemAdapter.php | 2 +- src/MountManager.php | 2 +- src/PhpseclibV3/SftpAdapter.php | 2 +- 9 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/AsyncAwsS3/AsyncAwsS3Adapter.php b/src/AsyncAwsS3/AsyncAwsS3Adapter.php index 7cd1c1757..0fd541aa7 100644 --- a/src/AsyncAwsS3/AsyncAwsS3Adapter.php +++ b/src/AsyncAwsS3/AsyncAwsS3Adapter.php @@ -318,7 +318,7 @@ public function copy(string $source, string $destination, Config $config): void $visibility = $config->get(Config::OPTION_VISIBILITY); - if ($visibility === null && $config->get('retain_visibility', true)) { + if ($visibility === null && $config->get(Config::OPTION_RETAIN_VISIBILITY, true)) { $visibility = $this->visibility($source)->visibility(); } } catch (Throwable $exception) { diff --git a/src/AwsS3V3/AwsS3V3Adapter.php b/src/AwsS3V3/AwsS3V3Adapter.php index 50ea8cc08..fefa3bb8e 100644 --- a/src/AwsS3V3/AwsS3V3Adapter.php +++ b/src/AwsS3V3/AwsS3V3Adapter.php @@ -417,7 +417,7 @@ public function copy(string $source, string $destination, Config $config): void try { $visibility = $config->get(Config::OPTION_VISIBILITY); - if ($visibility === null && $config->get('retain_visibility', true)) { + if ($visibility === null && $config->get(Config::OPTION_RETAIN_VISIBILITY, true)) { $visibility = $this->visibility($source)->visibility(); } } catch (Throwable $exception) { diff --git a/src/Config.php b/src/Config.php index 96fa7d63e..becf0478b 100644 --- a/src/Config.php +++ b/src/Config.php @@ -14,6 +14,7 @@ class Config public const OPTION_MOVE_IDENTICAL_PATH = 'move_destination_same_as_source'; public const OPTION_VISIBILITY = 'visibility'; public const OPTION_DIRECTORY_VISIBILITY = 'directory_visibility'; + public const OPTION_RETAIN_VISIBILITY = 'retain_visibility'; public function __construct(private array $options = []) { diff --git a/src/Filesystem.php b/src/Filesystem.php index 0ee74f269..5e42f3a89 100644 --- a/src/Filesystem.php +++ b/src/Filesystem.php @@ -264,7 +264,7 @@ private function rewindStream($resource): void private function resolveConfigForMoveAndCopy(array $config): Config { - $retainVisibility = $this->config->get('retain_visibility', $config['retain_visibility'] ?? true); + $retainVisibility = $this->config->get(Config::OPTION_RETAIN_VISIBILITY, $config[Config::OPTION_RETAIN_VISIBILITY] ?? true); $fullConfig = $this->config->extend($config); /* diff --git a/src/Ftp/FtpAdapter.php b/src/Ftp/FtpAdapter.php index 2d31cca0c..219a1b147 100644 --- a/src/Ftp/FtpAdapter.php +++ b/src/Ftp/FtpAdapter.php @@ -559,7 +559,7 @@ public function copy(string $source, string $destination, Config $config): void $readStream = $this->readStream($source); $visibility = $config->get(Config::OPTION_VISIBILITY); - if ($visibility === null && $config->get('retain_visibility', true)) { + if ($visibility === null && $config->get(Config::OPTION_RETAIN_VISIBILITY, true)) { $config = $config->withSetting(Config::OPTION_VISIBILITY, $this->visibility($source)->visibility()); } diff --git a/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php b/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php index 4bfc6b35c..95e5298f7 100644 --- a/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php +++ b/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php @@ -349,7 +349,7 @@ public function copy(string $source, string $destination, Config $config): void try { $visibility = $config->get(Config::OPTION_VISIBILITY); - if ($visibility === null && $config->get('retain_visibility', true)) { + if ($visibility === null && $config->get(Config::OPTION_RETAIN_VISIBILITY, true)) { $visibility = $this->visibility($source)->visibility(); } diff --git a/src/Local/LocalFilesystemAdapter.php b/src/Local/LocalFilesystemAdapter.php index 9edc39f6e..59720f37d 100644 --- a/src/Local/LocalFilesystemAdapter.php +++ b/src/Local/LocalFilesystemAdapter.php @@ -272,7 +272,7 @@ public function copy(string $source, string $destination, Config $config): void $visibility = $config->get( Config::OPTION_VISIBILITY, - $config->get('retain_visibility', true) + $config->get(Config::OPTION_RETAIN_VISIBILITY, true) ? $this->visibility($source)->visibility() : null, ); diff --git a/src/MountManager.php b/src/MountManager.php index 3dcfd234c..6474eeeee 100644 --- a/src/MountManager.php +++ b/src/MountManager.php @@ -373,7 +373,7 @@ private function copyAcrossFilesystem( array $config, ): void { $config = $this->config->extend($config); - $retainVisibility = (bool) $config->get('retain_visibility', true); + $retainVisibility = (bool) $config->get(Config::OPTION_RETAIN_VISIBILITY, true); $visibility = $config->get('visibility'); try { diff --git a/src/PhpseclibV3/SftpAdapter.php b/src/PhpseclibV3/SftpAdapter.php index 128f0eaa3..b47ed0695 100644 --- a/src/PhpseclibV3/SftpAdapter.php +++ b/src/PhpseclibV3/SftpAdapter.php @@ -329,7 +329,7 @@ public function copy(string $source, string $destination, Config $config): void $readStream = $this->readStream($source); $visibility = $config->get(Config::OPTION_VISIBILITY); - if ($visibility === null && $config->get('retain_visibility', true)) { + if ($visibility === null && $config->get(Config::OPTION_RETAIN_VISIBILITY, true)) { $config = $config->withSetting(Config::OPTION_VISIBILITY, $this->visibility($source)->visibility()); } From 22b77fa5c31ec739e994cfe37197913da4b90ad4 Mon Sep 17 00:00:00 2001 From: Jesper Noordsij Date: Sat, 18 Nov 2023 15:00:00 +0100 Subject: [PATCH 2/2] Replace various string-references to config options with consts --- src/AsyncAwsS3/AsyncAwsS3Adapter.php | 4 ++-- src/AwsS3V3/AwsS3V3Adapter.php | 4 ++-- src/Ftp/FtpAdapter.php | 2 +- src/MountManager.php | 4 ++-- src/PhpseclibV2/SftpAdapter.php | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/AsyncAwsS3/AsyncAwsS3Adapter.php b/src/AsyncAwsS3/AsyncAwsS3Adapter.php index 0fd541aa7..cfa11910c 100644 --- a/src/AsyncAwsS3/AsyncAwsS3Adapter.php +++ b/src/AsyncAwsS3/AsyncAwsS3Adapter.php @@ -197,8 +197,8 @@ public function deleteDirectory(string $path): void public function createDirectory(string $path, Config $config): void { - $defaultVisibility = $config->get('directory_visibility', $this->visibility->defaultForDirectories()); - $config = $config->withDefaults(['visibility' => $defaultVisibility]); + $defaultVisibility = $config->get(Config::OPTION_DIRECTORY_VISIBILITY, $this->visibility->defaultForDirectories()); + $config = $config->withDefaults([Config::OPTION_VISIBILITY => $defaultVisibility]); $this->upload(rtrim($path, '/') . '/', '', $config); } diff --git a/src/AwsS3V3/AwsS3V3Adapter.php b/src/AwsS3V3/AwsS3V3Adapter.php index fefa3bb8e..479332121 100644 --- a/src/AwsS3V3/AwsS3V3Adapter.php +++ b/src/AwsS3V3/AwsS3V3Adapter.php @@ -244,8 +244,8 @@ public function deleteDirectory(string $path): void public function createDirectory(string $path, Config $config): void { - $defaultVisibility = $config->get('directory_visibility', $this->visibility->defaultForDirectories()); - $config = $config->withDefaults(['visibility' => $defaultVisibility]); + $defaultVisibility = $config->get(Config::OPTION_DIRECTORY_VISIBILITY, $this->visibility->defaultForDirectories()); + $config = $config->withDefaults([Config::OPTION_VISIBILITY => $defaultVisibility]); $this->upload(rtrim($path, '/') . '/', '', $config); } diff --git a/src/Ftp/FtpAdapter.php b/src/Ftp/FtpAdapter.php index 219a1b147..079dd010a 100644 --- a/src/Ftp/FtpAdapter.php +++ b/src/Ftp/FtpAdapter.php @@ -251,7 +251,7 @@ public function deleteDirectory(string $path): void public function createDirectory(string $path, Config $config): void { - $this->ensureDirectoryExists($path, $config->get('directory_visibility', $config->get('visibility'))); + $this->ensureDirectoryExists($path, $config->get(Config::OPTION_DIRECTORY_VISIBILITY, $config->get(Config::OPTION_VISIBILITY))); } public function setVisibility(string $path, string $visibility): void diff --git a/src/MountManager.php b/src/MountManager.php index 6474eeeee..0fa7d8903 100644 --- a/src/MountManager.php +++ b/src/MountManager.php @@ -374,7 +374,7 @@ private function copyAcrossFilesystem( ): void { $config = $this->config->extend($config); $retainVisibility = (bool) $config->get(Config::OPTION_RETAIN_VISIBILITY, true); - $visibility = $config->get('visibility'); + $visibility = $config->get(Config::OPTION_VISIBILITY); try { if ($visibility == null && $retainVisibility) { @@ -382,7 +382,7 @@ private function copyAcrossFilesystem( } $stream = $sourceFilesystem->readStream($sourcePath); - $destinationFilesystem->writeStream($destinationPath, $stream, $visibility ? compact('visibility') : []); + $destinationFilesystem->writeStream($destinationPath, $stream, $visibility ? compact(Config::OPTION_VISIBILITY) : []); } catch (UnableToRetrieveMetadata | UnableToReadFile | UnableToWriteFile $exception) { throw UnableToCopyFile::fromLocationTo($source, $destination, $exception); } diff --git a/src/PhpseclibV2/SftpAdapter.php b/src/PhpseclibV2/SftpAdapter.php index a9560f843..e41f29c73 100644 --- a/src/PhpseclibV2/SftpAdapter.php +++ b/src/PhpseclibV2/SftpAdapter.php @@ -348,7 +348,7 @@ public function copy(string $source, string $destination, Config $config): void try { $readStream = $this->readStream($source); $visibility = $this->visibility($source)->visibility(); - $this->writeStream($destination, $readStream, new Config(compact('visibility'))); + $this->writeStream($destination, $readStream, new Config(compact(Config::OPTION_VISIBILITY))); } catch (Throwable $exception) { if (isset($readStream) && is_resource($readStream)) { @fclose($readStream);