Centum\Filter

Filters are used to transform one value into another. They are especially useful in validation, allowing you to standardize or sanitize a value before validating it.

All filters must implement Centum\Interfaces\Filter\FilterInterface.

Filters only require one public method:

  • filter(mixed $value): mixed Accepts any input and returns the filtered output.

You can leave the return value of filter() as mixed or you can be more specific, for example:

namespace App\Filters;

use Centum\Interfaces\Filter\FilterInterface;

class ArrayFilter implements FilterInterface
{
    public function filter(mixed $value): array
    {
        return [$value];
    }
}

Table of contents