From ea501a54e91754556f213ddfd7cfc05858917db0 Mon Sep 17 00:00:00 2001 From: Pieter Hoste Date: Thu, 11 Apr 2024 09:08:44 +0200 Subject: [PATCH] Fixes regression, Allow callbacks to be a FilterInterface again. Signed-off-by: Pieter Hoste --- src/FilterChain.php | 4 ++-- test/FilterChainTest.php | 8 +++++--- test/TestAsset/StrRepeatFilterInterface.php | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 test/TestAsset/StrRepeatFilterInterface.php diff --git a/src/FilterChain.php b/src/FilterChain.php index 4c092ed2..8343becb 100644 --- a/src/FilterChain.php +++ b/src/FilterChain.php @@ -29,7 +29,7 @@ * priority?: int, * }>, * callbacks?: list * } @@ -87,7 +87,7 @@ public function setOptions($options) foreach ($value as $spec) { $callback = $spec['callback'] ?? false; $priority = $spec['priority'] ?? static::DEFAULT_PRIORITY; - if (is_callable($callback)) { + if (is_callable($callback) || $callback instanceof FilterInterface) { $this->attach($callback, $priority); } } diff --git a/test/FilterChainTest.php b/test/FilterChainTest.php index 33b3df7f..3280692a 100644 --- a/test/FilterChainTest.php +++ b/test/FilterChainTest.php @@ -10,6 +10,7 @@ use Laminas\Filter\StringToLower; use Laminas\Filter\StringTrim; use Laminas\Filter\StripTags; +use LaminasTest\Filter\TestAsset\StrRepeatFilterInterface; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; @@ -77,7 +78,7 @@ public function testAllowsConfiguringFilters(): void $chain = new FilterChain(); $chain->setOptions($config); $value = ' abc '; - $valueExpected = 'ABC '; + $valueExpected = 'ABC ABC '; self::assertSame($valueExpected, $chain->filter($value)); } @@ -86,7 +87,7 @@ public function testAllowsConfiguringFiltersViaConstructor(): void $config = $this->getChainConfig(); $chain = new FilterChain($config); $value = ' abc '; - $valueExpected = 'ABC'; + $valueExpected = 'ABCABC'; self::assertSame($valueExpected, $chain->filter($value)); } @@ -96,7 +97,7 @@ public function testConfigurationAllowsTraversableObjects(): void $config = new ArrayIterator($config); $chain = new FilterChain($config); $value = ' abc '; - $valueExpected = 'ABC'; + $valueExpected = 'ABCABC'; self::assertSame($valueExpected, $chain->filter($value)); } @@ -117,6 +118,7 @@ private function getChainConfig(): array return [ 'callbacks' => [ ['callback' => [self::class, 'staticUcaseFilter']], + ['callback' => new StrRepeatFilterInterface()], [ 'priority' => 10000, 'callback' => static fn(string $value): string => trim($value), diff --git a/test/TestAsset/StrRepeatFilterInterface.php b/test/TestAsset/StrRepeatFilterInterface.php new file mode 100644 index 00000000..0912fe86 --- /dev/null +++ b/test/TestAsset/StrRepeatFilterInterface.php @@ -0,0 +1,17 @@ +