From d7fb37aff9817a23928ba28d03d10d2277fab985 Mon Sep 17 00:00:00 2001 From: Peter Jaap Blaakmeer Date: Sun, 26 Nov 2023 19:42:18 +0100 Subject: [PATCH 1/4] Allow setting custom options --- src/OptionSet.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OptionSet.php b/src/OptionSet.php index 1cc5fa9..e7a1751 100644 --- a/src/OptionSet.php +++ b/src/OptionSet.php @@ -13,7 +13,7 @@ class OptionSet */ private $options = []; - private function set(string $name, ...$args): self + public function set(string $name, ...$args): self { $this->options[$name] = $args; return $this; From b8ef8bdd200cd0b0edae817818e2570ba786428e Mon Sep 17 00:00:00 2001 From: peterjaap Date: Mon, 27 Nov 2023 15:39:44 +0100 Subject: [PATCH 2/4] Added setUnsafe method, added test --- src/OptionSet.php | 7 ++++++- test/OptionSetTest.php | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/OptionSet.php b/src/OptionSet.php index e7a1751..e2ce4a2 100644 --- a/src/OptionSet.php +++ b/src/OptionSet.php @@ -13,12 +13,17 @@ class OptionSet */ private $options = []; - public function set(string $name, ...$args): self + private function set(string $name, ...$args): self { $this->options[$name] = $args; return $this; } + public function setUnsafe(string $name, ...$args): self + { + return $this->set($name, ...$args); + } + public function unset(string $name): self { unset($this->options[$name]); diff --git a/test/OptionSetTest.php b/test/OptionSetTest.php index 98e3c32..379d22f 100644 --- a/test/OptionSetTest.php +++ b/test/OptionSetTest.php @@ -11,6 +11,7 @@ use Imgproxy\UnsharpeningMode; use Imgproxy\WatermarkPosition; use PHPUnit\Framework\TestCase; +use ReflectionClass; class OptionSetTest extends TestCase { @@ -973,6 +974,23 @@ public function testWithQuality() $this->assertEquals(70, $os->quality()); } + public function testSetUnsafe(): void + { + $os = new OptionSet(); + $optionName = 'zoom'; + $args = ['2', '2']; + + $os->setUnsafe($optionName, ...$args); + + $reflectionClass = new ReflectionClass(OptionSet::class); + $optionsProperty = $reflectionClass->getProperty('options'); + $optionsProperty->setAccessible(true); + $options = $optionsProperty->getValue($os); + + $this->assertArrayHasKey($optionName, $options); + $this->assertSame($args, $options[$optionName]); + } + public function testUnset() { $os = new OptionSet(); From 6047b8b676eac722071957b6a6771aeab5eca799 Mon Sep 17 00:00:00 2001 From: peterjaap Date: Mon, 27 Nov 2023 15:44:12 +0100 Subject: [PATCH 3/4] Keep set method private --- src/OptionSet.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OptionSet.php b/src/OptionSet.php index e2ce4a2..349bf1f 100644 --- a/src/OptionSet.php +++ b/src/OptionSet.php @@ -13,7 +13,7 @@ class OptionSet */ private $options = []; - private function set(string $name, ...$args): self + public function set(string $name, ...$args): self { $this->options[$name] = $args; return $this; From c92a727354931bc1fa65d3e7c10dcbca9fe869b3 Mon Sep 17 00:00:00 2001 From: peterjaap Date: Mon, 27 Nov 2023 15:44:57 +0100 Subject: [PATCH 4/4] Keep set method private --- src/OptionSet.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OptionSet.php b/src/OptionSet.php index 349bf1f..e2ce4a2 100644 --- a/src/OptionSet.php +++ b/src/OptionSet.php @@ -13,7 +13,7 @@ class OptionSet */ private $options = []; - public function set(string $name, ...$args): self + private function set(string $name, ...$args): self { $this->options[$name] = $args; return $this;