1 | <?php |
||
24 | trait RowFilter |
||
25 | { |
||
26 | /** |
||
27 | * Callables to validate the row before insertion |
||
28 | * |
||
29 | * @var callable[] |
||
30 | */ |
||
31 | protected $validators = []; |
||
32 | |||
33 | /** |
||
34 | * Callables to format the row before insertion |
||
35 | * |
||
36 | * @var callable[] |
||
37 | */ |
||
38 | protected $formatters = []; |
||
39 | |||
40 | /** |
||
41 | * add a formatter to the collection |
||
42 | * |
||
43 | * @param callable $callable |
||
44 | * |
||
45 | * @return $this |
||
46 | */ |
||
47 | 6 | public function addFormatter(callable $callable) |
|
53 | |||
54 | /** |
||
55 | * Remove a formatter from the collection |
||
56 | * |
||
57 | * @param callable $callable |
||
58 | * |
||
59 | * @return $this |
||
60 | */ |
||
61 | 3 | public function removeFormatter(callable $callable) |
|
68 | |||
69 | /** |
||
70 | * Detect if the formatter is already registered |
||
71 | * |
||
72 | * @param callable $callable |
||
73 | * |
||
74 | * @return bool |
||
75 | */ |
||
76 | 3 | public function hasFormatter(callable $callable) |
|
80 | |||
81 | /** |
||
82 | * Remove all registered formatter |
||
83 | * |
||
84 | * @return $this |
||
85 | */ |
||
86 | 3 | public function clearFormatters() |
|
92 | |||
93 | /** |
||
94 | * add a Validator to the collection |
||
95 | * |
||
96 | * @param callable $callable |
||
97 | * @param string $name the rule name |
||
98 | * |
||
99 | * @return $this |
||
100 | */ |
||
101 | 12 | public function addValidator(callable $callable, $name) |
|
109 | |||
110 | /** |
||
111 | * @inheritdoc |
||
112 | */ |
||
113 | abstract protected function validateString($str); |
||
114 | |||
115 | /** |
||
116 | * Remove a validator from the collection |
||
117 | * |
||
118 | * @param string $name the validator name |
||
119 | * |
||
120 | * @return $this |
||
121 | */ |
||
122 | 3 | public function removeValidator($name) |
|
129 | |||
130 | /** |
||
131 | * Detect if a validator is already registered |
||
132 | * |
||
133 | * @param string $name the validator name |
||
134 | * |
||
135 | * @return bool |
||
136 | */ |
||
137 | 3 | public function hasValidator($name) |
|
143 | |||
144 | /** |
||
145 | * Remove all registered validators |
||
146 | * |
||
147 | * @return $this |
||
148 | */ |
||
149 | 3 | public function clearValidators() |
|
155 | |||
156 | /** |
||
157 | * Format the given row |
||
158 | * |
||
159 | * @param array $row |
||
160 | * |
||
161 | * @return array |
||
162 | */ |
||
163 | 39 | protected function formatRow(array $row) |
|
171 | |||
172 | /** |
||
173 | * Validate a row |
||
174 | * |
||
175 | * @param array $row |
||
176 | * |
||
177 | * @throws InvalidRowException If the validation failed |
||
178 | */ |
||
179 | 39 | protected function validateRow(array $row) |
|
187 | } |
||
188 |