fg / cascade
A lightweight API to filter values.
1.0.0
2015-04-05 16:59 UTC
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2024-10-24 04:24:58 UTC
README
A lightweight API to filter values.
Installation
composer require fg/cascade
Usage
Filtering a value:
$Cascade = new Cascade\Cascade([ function($value) { return $value + $value; }, function($value) { return $value * $value; } ]); echo $Cascade->filter(2); // 16
Filtering a value depending on additionnal arguments:
$Cascade = new Cascade\Cascade([ function($value, $factor) { return $value * $factor; } ]); echo $Cascade->filter(2, 10); // 20
Filtering a value with a filter object:
class SquareFilter { public function __invoke($value) { return $value * $value; } } $Cascade = new Cascade\Cascade([ new SquareFilter() ]); echo $Cascade->filter(2); // 4
API
// constructor $Cascade = new Cascade\Cascade(); $Cascade = new Cascade\Cascade($filters); // accessors for the list of filters $Cascade->filters(); $Cascade->setFilters($filters); $Cascade->addFilter($filter); // filter $Cascade->filter($value [, $args...]);