-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactors filter chain to require the plugin manager as a constructor dependency and… - Drops `setOptions` - Removes inheritance - Implement newly added `FilterChainInterface` - Remove the constant `DEFAULT_PRIORITY` - Drops getter and setter for the plugin manager - Drops the `plugin` method - Drops `getFilter` - Stops pretending that chains can be serialized Introduces `ImmutableFilterChain` which is effectively the same as `FilterChain` but immutable and lacks the `merge` method which has limited use cases. `ImmutableFilterChain` and `FilterChainInterface` can be backported to 2.x so that libs can switch to it (input-filter, form etc) without breaking BC _(Possibly)_ Signed-off-by: George Steel <[email protected]>
- Loading branch information
Showing
11 changed files
with
525 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Laminas\Filter; | ||
|
||
use Laminas\ServiceManager\Factory\FactoryInterface; | ||
use Psr\Container\ContainerInterface; | ||
|
||
use function assert; | ||
|
||
/** @psalm-import-type FilterChainConfiguration from FilterChain */ | ||
final class FilterChainFactory implements FactoryInterface | ||
{ | ||
public function __invoke(ContainerInterface $container, string $requestedName, ?array $options = null): FilterChain | ||
{ | ||
/** | ||
* It's not worth attempting runtime validation of the specification shape | ||
* @psalm-var FilterChainConfiguration $options | ||
*/ | ||
$options = $options ?? []; | ||
$pluginManager = $container->get(FilterPluginManager::class); | ||
assert($pluginManager instanceof FilterPluginManager); | ||
|
||
return new FilterChain($pluginManager, $options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Laminas\Filter; | ||
|
||
use Psr\Container\ContainerExceptionInterface; | ||
|
||
/** | ||
* @template TFilteredValue | ||
* @extends FilterInterface<TFilteredValue> | ||
* @psalm-type InstanceType = FilterInterface|callable(mixed): mixed | ||
*/ | ||
interface FilterChainInterface extends FilterInterface | ||
{ | ||
public const DEFAULT_PRIORITY = 1000; | ||
|
||
/** | ||
* Attach a filter to the chain | ||
* | ||
* @param InstanceType $callback A Filter implementation or valid PHP callback | ||
* @param int $priority Priority at which to enqueue filter; defaults to 1000 (higher executes earlier) | ||
*/ | ||
public function attach(FilterInterface|callable $callback, int $priority = self::DEFAULT_PRIORITY): self; | ||
|
||
/** | ||
* Attach a filter to the chain using an alias or FQCN | ||
* | ||
* Retrieves the filter from the composed plugin manager, and then calls attach() | ||
* with the retrieved instance. | ||
* | ||
* @param class-string<FilterInterface>|string $name | ||
* @param array<string, mixed> $options Construction options for the desired filter | ||
* @param int $priority Priority at which to enqueue filter; defaults to 1000 (higher executes earlier) | ||
* @throws ContainerExceptionInterface If the filter cannot be retrieved from the plugin manager. | ||
*/ | ||
public function attachByName(string $name, array $options = [], int $priority = self::DEFAULT_PRIORITY): self; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.