1 | <?php |
||
28 | class Filter implements Reducer |
||
29 | { |
||
30 | /** |
||
31 | * @var array<string,\Caridea\Filter\Chain> - The filters keyed by field |
||
32 | */ |
||
33 | protected $chains = []; |
||
34 | /** |
||
35 | * @var array<\Caridea\Filter\Reducer> - The reducers |
||
36 | */ |
||
37 | protected $reducers = []; |
||
38 | /** |
||
39 | * @var \Caridea\Filter\Chain - The chain to run if field is unregistered |
||
40 | */ |
||
41 | protected $otherwise; |
||
42 | |||
43 | /** |
||
44 | * Creates a new Filter (but you're probably better off using `Builder`). |
||
45 | * |
||
46 | * Any `Chain`s supplied to this method will be cloned. Modifications to the |
||
47 | * originals will not appear once a `Filter` is constructed. |
||
48 | * |
||
49 | * @param array<string,\Caridea\Filter\Chain> $chains - The filters keyed by field |
||
50 | * @param array<\Caridea\Filter\Reducer> $reducers - Any Reducer filters to include |
||
51 | * @param \Caridea\Filter\Chain $otherwise - The chain to run for missing fields |
||
52 | */ |
||
53 | 4 | public function __construct(array $chains, array $reducers = [], Chain $otherwise = null) |
|
69 | |||
70 | /** |
||
71 | * Runs the array filter. |
||
72 | * |
||
73 | * Chains are run in the order in which they were inserted. Reducers are run |
||
74 | * afterward and operate on the filtered values. Each reducer is run |
||
75 | * sequentially and operates on the values returned from the previous. |
||
76 | * |
||
77 | * @param array<string,mixed> $values The values to filter |
||
78 | * @return array The filtered array |
||
79 | */ |
||
80 | 2 | public function __invoke(array $values): array |
|
99 | } |
||
100 |