Search by

wilycode / filter

szymonpietrek-design

Small filter contract for reusable value normalization.

Package info

github.com/wilycode/filter

pkg:composer/wilycode/filter

Statistics

Installs: 12

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.0 2026-10-25 23:59 UTC

This package is auto-updated.

Last update: 2026-10-26 00:02:40 UTC


README

PHP 8.4+ MIT License Tests

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.

Explore the WilyCode PHP Ecosystem →

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.