| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace League\Flysystem; |
| 6 |
|
| 7 |
use function array_diff_key; |
| 8 |
use function array_flip; |
| 9 |
use function array_merge; |
| 10 |
|
| 11 |
class Config |
| 12 |
{ |
| 13 |
public const OPTION_COPY_IDENTICAL_PATH = 'copy_destination_same_as_source'; |
| 14 |
public const OPTION_MOVE_IDENTICAL_PATH = 'move_destination_same_as_source'; |
| 15 |
public const OPTION_VISIBILITY = 'visibility'; |
| 16 |
public const OPTION_DIRECTORY_VISIBILITY = 'directory_visibility'; |
| 17 |
public const OPTION_RETAIN_VISIBILITY = 'retain_visibility'; |
| 18 |
|
| 19 |
public function __construct(private array $options = []) |
| 20 |
{ |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* @param mixed $default |
| 25 |
* |
| 26 |
* @return mixed |
| 27 |
*/ |
| 28 |
public function get(string $property, $default = null) |
| 29 |
{ |
| 30 |
return $this->options[$property] ?? $default; |
| 31 |
} |
| 32 |
|
| 33 |
public function extend(array $options): Config |
| 34 |
{ |
| 35 |
return new Config(array_merge($this->options, $options)); |
| 36 |
} |
| 37 |
|
| 38 |
public function withDefaults(array $defaults): Config |
| 39 |
{ |
| 40 |
return new Config($this->options + $defaults); |
| 41 |
} |
| 42 |
|
| 43 |
public function toArray(): array |
| 44 |
{ |
| 45 |
return $this->options; |
| 46 |
} |
| 47 |
|
| 48 |
public function withSetting(string $property, mixed $setting): Config |
| 49 |
{ |
| 50 |
return $this->extend([$property => $setting]); |
| 51 |
} |
| 52 |
|
| 53 |
public function withoutSettings(string ...$settings): Config |
| 54 |
{ |
| 55 |
return new Config(array_diff_key($this->options, array_flip($settings))); |
| 56 |
} |
| 57 |
} |
| 58 |
|