Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge release 2.35.2 into 2.36.x #141

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/FilterChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* priority?: int,
* }>,
* callbacks?: list<array{
* callback: callable(mixed): mixed,
* callback: FilterInterface|callable(mixed): mixed,
* priority?: int,
* }>
* }
Expand Down Expand Up @@ -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);
}
}
Expand Down
8 changes: 5 additions & 3 deletions test/FilterChainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -77,7 +78,7 @@ public function testAllowsConfiguringFilters(): void
$chain = new FilterChain();
$chain->setOptions($config);
$value = '<a name="foo"> abc </a><img id="bar" />';
$valueExpected = 'ABC <IMG ID="BAR" />';
$valueExpected = 'ABC <IMG ID="BAR" />ABC <IMG ID="BAR" />';
self::assertSame($valueExpected, $chain->filter($value));
}

Expand All @@ -86,7 +87,7 @@ public function testAllowsConfiguringFiltersViaConstructor(): void
$config = $this->getChainConfig();
$chain = new FilterChain($config);
$value = '<a name="foo"> abc </a>';
$valueExpected = 'ABC';
$valueExpected = 'ABCABC';
self::assertSame($valueExpected, $chain->filter($value));
}

Expand All @@ -96,7 +97,7 @@ public function testConfigurationAllowsTraversableObjects(): void
$config = new ArrayIterator($config);
$chain = new FilterChain($config);
$value = '<a name="foo"> abc </a>';
$valueExpected = 'ABC';
$valueExpected = 'ABCABC';
self::assertSame($valueExpected, $chain->filter($value));
}

Expand All @@ -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),
Expand Down
17 changes: 17 additions & 0 deletions test/TestAsset/StrRepeatFilterInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace LaminasTest\Filter\TestAsset;

use Laminas\Filter\FilterInterface;

use function str_repeat;

class StrRepeatFilterInterface implements FilterInterface
{
public function filter($value)
{
return str_repeat((string) $value, 2);
}
}