Skip to content

Commit

Permalink
Merge pull request #1732 from jnoordsij/add-config-key-constant
Browse files Browse the repository at this point in the history
frankdejonge authored Nov 18, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents e78a8fa + 22b77fa commit 2c02112
Showing 10 changed files with 17 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/AsyncAwsS3/AsyncAwsS3Adapter.php
Original file line number Diff line number Diff line change
@@ -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);
}

@@ -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) {
6 changes: 3 additions & 3 deletions src/AwsS3V3/AwsS3V3Adapter.php
Original file line number Diff line number Diff line change
@@ -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);
}

@@ -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) {
1 change: 1 addition & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
@@ -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 = [])
{
2 changes: 1 addition & 1 deletion src/Filesystem.php
Original file line number Diff line number Diff line change
@@ -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);

/*
4 changes: 2 additions & 2 deletions src/Ftp/FtpAdapter.php
Original file line number Diff line number Diff line change
@@ -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
@@ -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());
}

2 changes: 1 addition & 1 deletion src/GoogleCloudStorage/GoogleCloudStorageAdapter.php
Original file line number Diff line number Diff line change
@@ -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();
}

2 changes: 1 addition & 1 deletion src/Local/LocalFilesystemAdapter.php
Original file line number Diff line number Diff line change
@@ -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,
);
6 changes: 3 additions & 3 deletions src/MountManager.php
Original file line number Diff line number Diff line change
@@ -373,16 +373,16 @@ private function copyAcrossFilesystem(
array $config,
): void {
$config = $this->config->extend($config);
$retainVisibility = (bool) $config->get('retain_visibility', true);
$visibility = $config->get('visibility');
$retainVisibility = (bool) $config->get(Config::OPTION_RETAIN_VISIBILITY, true);
$visibility = $config->get(Config::OPTION_VISIBILITY);

try {
if ($visibility == null && $retainVisibility) {
$visibility = $sourceFilesystem->visibility($sourcePath);
}

$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);
}
2 changes: 1 addition & 1 deletion src/PhpseclibV2/SftpAdapter.php
Original file line number Diff line number Diff line change
@@ -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);
2 changes: 1 addition & 1 deletion src/PhpseclibV3/SftpAdapter.php
Original file line number Diff line number Diff line change
@@ -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());
}

0 comments on commit 2c02112

Please sign in to comment.