wilycode / filter
Small filter contract for reusable value normalization.
Requires
- php: ^8.4
Requires (Dev)
- phpunit/phpunit: ^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-26 00:02:40 UTC
README
A minimal, framework-independent contract for normalizing PHP values. This package defines an interface only, keeping applications independent of specific filters.
WilyCode PHP Ecosystem
Part of WilyCode — independent PHP libraries with their own repositories, releases and Composer installation.
Contents
Installation
Requires PHP 8.4+. There are no additional runtime dependencies.
composer require wilycode/filter
Implement a filter
<?php declare(strict_types=1); require __DIR__ . '/vendor/autoload.php'; use WilyCode\Filter\FilterInterface; final class UppercasePrefixFilter implements FilterInterface { public function getFilteredValue(mixed $value): mixed { if (!is_string($value)) { return $value; } return 'PREFIX-' . strtoupper($value); } } $filter = new UppercasePrefixFilter(); $filter->getFilteredValue('hello'); // 'PREFIX-HELLO' $filter->getFilteredValue(null); // null
FilterInterface has a single method, getFilteredValue(mixed $value): mixed. Its return type deliberately allows normalization to change the input type, such as converting a form string to an integer or null. Decide how to handle non-matching input types in your own implementation.
API reference
| API | Purpose |
|---|---|
FilterInterface::getFilteredValue(mixed $value): mixed |
Return a normalized value. |
The contract has no filtering pipeline, validation side effects or built-in error reporting. Consumers choose when to invoke a filter.
Related packages
wilycode/filters— ready-made trim, null, scalar type, string case, array-item and slug filters.wilycode/form— form fields and nested groups that consume filters and validators.
Development
composer install
composer validate --strict
composer test
The GitHub Actions workflow tests PHP 8.4 and PHP 8.5. Source tests are excluded from Composer distribution archives.
License
MIT © 2026 Simon Piter. See LICENSE.