Centum\Filter

Filters are used to transform one value into another. They are very useful in validation as it allows you to standardise a value before validating it.

Filters must implement Centum\Interfaces\Filter\FilterInterface.

Filters only require one public method:

  • filter(mixed $value): mixed

The filter() method takes an input of any data type and return a filtered output of any type. You can leave the return value 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