diff --git a/src/Config.php b/src/Config.php index 691f9b63d..96fa7d63e 100644 --- a/src/Config.php +++ b/src/Config.php @@ -4,6 +4,8 @@ namespace League\Flysystem; +use function array_diff_key; +use function array_flip; use function array_merge; class Config @@ -46,4 +48,9 @@ public function withSetting(string $property, mixed $setting): Config { return $this->extend([$property => $setting]); } + + public function withoutSettings(string ...$settings): Config + { + return new Config(array_diff_key($this->options, array_flip($settings))); + } } diff --git a/src/ConfigTest.php b/src/ConfigTest.php index fa399adef..81c8958e9 100644 --- a/src/ConfigTest.php +++ b/src/ConfigTest.php @@ -53,4 +53,19 @@ public function extending_with_defaults(): void $this->assertEquals('set', $withDefaults->get('option')); $this->assertEquals('default', $withDefaults->get('other')); } + + /** + * @test + */ + public function extending_without_settings(): void + { + // arrange + $config = new Config(['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4]); + + // act + $withoutSetting = $config->withoutSettings('b', 'd'); + + // assert + $this->assertEquals(['a' => 1, 'c' => 3], $withoutSetting->toArray()); + } }