componenta/filter

Composable filters for Componenta class discovery and reflection workflows

Maintainers

Package info

github.com/componenta/filter

pkg:composer/componenta/filter

Statistics

Installs: 7

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-15 10:58 UTC

This package is auto-updated.

Last update: 2026-06-15 12:06:40 UTC


README

Composable filter objects for iterable data and reflection/class discovery.

Installation

composer require componenta/filter

Requirements

  • PHP 8.4+
  • componenta/arrayable

Related Packages

Package Why it matters here
componenta/arrayable Filters can expose their result through toArray().
componenta/class-finder Uses filters to select discovered classes, attributes, and reflection targets.
componenta/iterator Can combine filtering with replayable iteration.

What It Provides

  • FilterInterface: iterable filter contract with accept() and toArray().
  • AbstractFilter: base implementation for filtering an iterable source.
  • FilterableInterface and Filterable: immutable filter-chain support.
  • Concrete filters for scalars, arrays, strings, class names, reflection objects, files, ranges, callbacks, and composition.

Basic Usage

use Componenta\Filter\StringFilter;

$filter = new StringFilter(['one', 2, 'three']);

$filter->toArray(); // ['one', 'three']

Keys are not preserved by default:

$filter->toArray(preserveKeys: true);

Custom Criteria

use Componenta\Filter\CallbackFilter;

$filter = new CallbackFilter(
    static fn(mixed $value, string|int|null $key): bool => is_int($value) && $value > 10,
    [5, 15, 20],
);

$filter->toArray(); // [15, 20]

Filter Chains

Objects using Filterable should return new instances when filters are added or removed.

$next = $filterable->withFilter($filter);
$sameWithout = $next->withoutFilter($filter);

accept() uses AND semantics: every registered filter must accept the value.