Skip to content

Commit

Permalink
Allow removing settings from config.
Browse files Browse the repository at this point in the history
  • Loading branch information
frankdejonge committed Nov 7, 2023
1 parent 11571a7 commit 6637bdc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace League\Flysystem;

use function array_diff_key;
use function array_flip;
use function array_merge;

class Config
Expand Down Expand Up @@ -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)));
}
}
15 changes: 15 additions & 0 deletions src/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 6637bdc

Please sign in to comment.