Skip to content

Commit

Permalink
Merge pull request #141 from laminas/2.35.x-merge-up-into-2.36.x_qFWC…
Browse files Browse the repository at this point in the history
…JYLS

Merge release 2.35.2 into 2.36.x
  • Loading branch information
Xerkus committed Apr 11, 2024
2 parents f98ddcf + 3e821b3 commit adeef98
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/FilterChain.php
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
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
@@ -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);
}
}

0 comments on commit adeef98

Please sign in to comment.