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
  • Loading branch information
frankdejonge authored Nov 18, 2023
2 parents e78a8fa + 22b77fa commit 2c02112
Show file tree
Hide file tree
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
Expand Up @@ -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);
}

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

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/Local/LocalFilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
6 changes: 3 additions & 3 deletions src/MountManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/PhpseclibV2/SftpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/PhpseclibV3/SftpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down

0 comments on commit 2c02112

Please sign in to comment.