1 | <?php |
||
28 | class Chain implements \IteratorAggregate, \Countable |
||
29 | { |
||
30 | /** |
||
31 | * @var Registry - The builder containing definitions |
||
32 | */ |
||
33 | protected $registry; |
||
34 | /** |
||
35 | * @var callable[] - The filters to apply |
||
36 | */ |
||
37 | protected $filters = []; |
||
38 | /** |
||
39 | * @var bool - Whether to run this filter regardless of value existence |
||
40 | */ |
||
41 | protected $required; |
||
42 | |||
43 | /** |
||
44 | * Creates a new Chain |
||
45 | * |
||
46 | * @param \Caridea\Filter\Registry $registry The builder |
||
47 | * @param bool $required Whether these filters run even if value is missing |
||
48 | */ |
||
49 | 1 | public function __construct(Registry $registry, bool $required = false) |
|
54 | |||
55 | /** |
||
56 | * Run all of the filters. |
||
57 | * |
||
58 | * @param mixed $value The value to filter |
||
59 | * @return mixed The sanitized value |
||
60 | */ |
||
61 | 2 | public function __invoke($value) |
|
69 | |||
70 | /** |
||
71 | * Whether this set is empty. |
||
72 | * |
||
73 | * @return bool `true` if this set is empty |
||
74 | */ |
||
75 | 1 | public function isEmpty(): bool |
|
79 | |||
80 | /** |
||
81 | * Whether this set is required to run. |
||
82 | * |
||
83 | * @return bool `true` if this set is required |
||
84 | */ |
||
85 | 1 | public function isRequired(): bool |
|
89 | |||
90 | /** |
||
91 | * Gets the count. |
||
92 | * |
||
93 | * @return int The count |
||
94 | */ |
||
95 | 1 | public function count(): int |
|
99 | |||
100 | /** |
||
101 | * Gets the iterator. |
||
102 | * |
||
103 | * @return \Traversable The iterator |
||
104 | */ |
||
105 | 1 | public function getIterator(): \Traversable |
|
109 | |||
110 | /** |
||
111 | * Returns this chain with the defined filter appended. |
||
112 | * |
||
113 | * @param string $name The filter name |
||
114 | * @param mixed $args Any remaining arguments for the filter |
||
115 | * @return self provides a fluent interface |
||
116 | */ |
||
117 | 1 | public function then(string $name, ...$args): self |
|
122 | |||
123 | /** |
||
124 | * Returns this chain with the defined *each* filter appended. |
||
125 | * |
||
126 | * If the filter receives an array, it will run for every entry, and if it |
||
127 | * receives anything else, it will be run once. |
||
128 | * |
||
129 | * @param string $name The filter name |
||
130 | * @param mixed $args Any remaining arguments for the filter |
||
131 | * @return self provides a fluent interface |
||
132 | */ |
||
133 | 1 | public function each(string $name, ...$args): self |
|
141 | } |
||
142 |