1 | <?php |
||
26 | class Builder |
||
27 | { |
||
28 | /** |
||
29 | * @var \Caridea\Filter\Registry - The filter registry |
||
30 | */ |
||
31 | protected $registry; |
||
32 | /** |
||
33 | * @var array<string,\Caridea\Filter\Chain> - The chains by field name |
||
34 | */ |
||
35 | protected $chains = []; |
||
36 | /** |
||
37 | * |
||
38 | * @var \Caridea\Filter\Reducer[] |
||
39 | */ |
||
40 | protected $reducers = []; |
||
41 | /** |
||
42 | * @var \Caridea\Filter\Chain|null |
||
43 | */ |
||
44 | protected $otherwiseChain; |
||
45 | |||
46 | /** |
||
47 | * Creates a new Builder. |
||
48 | * |
||
49 | * @param \Caridea\Filter\Registry $registry The filter registry |
||
50 | */ |
||
51 | 1 | public function __construct(Registry $registry) |
|
55 | |||
56 | /** |
||
57 | * Creates a new Chain for a field |
||
58 | * |
||
59 | * @param string $name The field name |
||
60 | * @return \Caridea\Filter\Chain the chain |
||
61 | */ |
||
62 | 1 | public function field(string $name): Chain |
|
68 | |||
69 | /** |
||
70 | * Creates a new *required* Chain for a field. |
||
71 | * |
||
72 | * @param string $name The field name |
||
73 | * @return \Caridea\Filter\Chain the chain |
||
74 | */ |
||
75 | 1 | public function always(string $name): Chain |
|
81 | |||
82 | /** |
||
83 | * Adds a multiple filter to the builder. |
||
84 | * |
||
85 | * @param \Caridea\Filter\Reducer $multi |
||
86 | * @return self provides a fluent interface |
||
87 | */ |
||
88 | 1 | public function reducer(Reducer $multi): self |
|
93 | |||
94 | /** |
||
95 | * Adds a chain that runs for any non-mentioned fields. |
||
96 | * |
||
97 | * @param string $name The filter name |
||
98 | * @param mixed $args The filter arguments |
||
99 | * @return \Caridea\Filter\Chain the chain |
||
100 | */ |
||
101 | 1 | public function otherwise(string $name, ...$args): Chain |
|
107 | |||
108 | /** |
||
109 | * Builds a new Filter. |
||
110 | * |
||
111 | * @return \Caridea\Filter\Filter the created Filter. |
||
112 | */ |
||
113 | 1 | public function build(): Filter |
|
117 | } |
||
118 |