1 | <?php |
||
26 | class SubjectFilter |
||
27 | { |
||
28 | /** |
||
29 | * |
||
30 | * An array of specifications for the filter subject. |
||
31 | * |
||
32 | * @var array |
||
33 | * |
||
34 | */ |
||
35 | protected $specs = array(); |
||
36 | |||
37 | /** |
||
38 | * |
||
39 | * Skip these fields on the filter subject. |
||
40 | * |
||
41 | * @var array |
||
42 | * |
||
43 | */ |
||
44 | protected $skip = array(); |
||
45 | |||
46 | /** |
||
47 | * |
||
48 | * A collection of failure objects. |
||
49 | * |
||
50 | * @var FailureCollection |
||
51 | * |
||
52 | */ |
||
53 | protected $failures; |
||
54 | |||
55 | /** |
||
56 | * |
||
57 | * Use these field-specific messages when a subject field fails. |
||
58 | * |
||
59 | * @var array |
||
60 | * |
||
61 | */ |
||
62 | protected $field_messages = array(); |
||
63 | |||
64 | /** |
||
65 | * |
||
66 | * A prototype ValidateSpect. |
||
67 | * |
||
68 | * @var ValidateSpec |
||
69 | * |
||
70 | */ |
||
71 | protected $validate_spec; |
||
72 | |||
73 | /** |
||
74 | * |
||
75 | * A prototype SanitizeSpect. |
||
76 | * |
||
77 | * @var SanitizeSpec |
||
78 | * |
||
79 | */ |
||
80 | protected $sanitize_spec; |
||
81 | |||
82 | |||
83 | /** |
||
84 | * Factory for Sub subject specifications |
||
85 | * |
||
86 | * @var SubSpecFactory |
||
87 | * |
||
88 | * @access protected |
||
89 | */ |
||
90 | protected $sub_spec_factory; |
||
91 | |||
92 | /** |
||
93 | * |
||
94 | * A prototype FailureCollection. |
||
95 | * |
||
96 | * @var FailureCollection |
||
97 | * |
||
98 | */ |
||
99 | protected $proto_failures; |
||
100 | |||
101 | /** |
||
102 | * |
||
103 | * Constructor. |
||
104 | * |
||
105 | * @param ValidateSpec $validate_spec A prototype ValidateSpec. |
||
106 | * |
||
107 | * @param ValidateSpec $sanitize_spec A prototype SanitizeSpec. |
||
108 | * |
||
109 | * @param SubSpecFactory $sub_spec_factory A factory for SubSpec |
||
110 | * |
||
111 | * @param FailureCollection $failures A prototype FailureCollection. |
||
112 | * |
||
113 | * @return self |
||
|
|||
114 | * |
||
115 | */ |
||
116 | 10 | public function __construct( |
|
128 | |||
129 | /** |
||
130 | * |
||
131 | * Initialization logic for this filter. |
||
132 | * |
||
133 | * @return null |
||
134 | * |
||
135 | */ |
||
136 | 10 | protected function init() |
|
140 | |||
141 | /** |
||
142 | * |
||
143 | * Asserts that the subject passes the filter. |
||
144 | * |
||
145 | * @param array|object $subject The subject to be filtered. |
||
146 | * |
||
147 | * @return null |
||
148 | * |
||
149 | * @throws Exception\FilterFailed when the assertion fails. |
||
150 | * |
||
151 | */ |
||
152 | 2 | public function __invoke(&$subject) |
|
156 | |||
157 | /** |
||
158 | * |
||
159 | * Asserts that the subject passes the filter. |
||
160 | * |
||
161 | * @param array|object $subject The subject to be filtered. |
||
162 | * |
||
163 | * @return null |
||
164 | * |
||
165 | * @throws Exception\FilterFailed when the assertion fails. |
||
166 | * |
||
167 | */ |
||
168 | 2 | public function assert(&$subject) |
|
186 | |||
187 | /** |
||
188 | * |
||
189 | * Adds a "validate" specification for a subject field. |
||
190 | * |
||
191 | * @param string $field The subject field name. |
||
192 | * |
||
193 | * @return ValidateSpec |
||
194 | * |
||
195 | */ |
||
196 | 7 | public function validate($field) |
|
200 | |||
201 | /** |
||
202 | * |
||
203 | * Adds a "sanitize" specification for a subject field. |
||
204 | * |
||
205 | * @param string $field The subject field name. |
||
206 | * |
||
207 | * @return SanitizeSpec |
||
208 | * |
||
209 | */ |
||
210 | 3 | public function sanitize($field) |
|
214 | |||
215 | /** |
||
216 | * |
||
217 | * Adds a "subfilter" specification for a subject field. |
||
218 | * |
||
219 | * @param string $field The subject field name. |
||
220 | * |
||
221 | * @return SubSpec |
||
222 | * |
||
223 | */ |
||
224 | public function subfilter($field, $class = 'Aura\Filter\SubjectFilter') |
||
229 | |||
230 | /** |
||
231 | * |
||
232 | * Adds a specification for a subject field. |
||
233 | * |
||
234 | * @param Spec $spec The specification object. |
||
235 | * |
||
236 | * @param string $field The subject field name. |
||
237 | * |
||
238 | * @return Spec |
||
239 | * |
||
240 | */ |
||
241 | 9 | protected function addSpec($spec, $field) |
|
247 | |||
248 | /** |
||
249 | * |
||
250 | * Specifies a custom message to use when a subject field fails. |
||
251 | * |
||
252 | * @param string $field The subject field name. |
||
253 | * |
||
254 | * @param string $message The failure message to use. |
||
255 | * |
||
256 | * @return null |
||
257 | * |
||
258 | */ |
||
259 | 1 | public function useFieldMessage($field, $message) |
|
263 | |||
264 | /** |
||
265 | * |
||
266 | * Applies the filter to a subject. |
||
267 | * |
||
268 | * @param array|object $subject The subject to be filtered. |
||
269 | * |
||
270 | * @return bool True on success, false on failure. |
||
271 | * |
||
272 | */ |
||
273 | 10 | public function apply(&$subject) |
|
287 | |||
288 | /** |
||
289 | * |
||
290 | * Applies the rule specifications to an array. |
||
291 | * |
||
292 | * @param array $array The filter subject. |
||
293 | * |
||
294 | * @return bool True if all rules passed, false if not. |
||
295 | * |
||
296 | */ |
||
297 | 3 | protected function applyToArray(&$array) |
|
304 | |||
305 | /** |
||
306 | * |
||
307 | * Applies the rule specifications to an object. |
||
308 | * |
||
309 | * @param object $object The filter subject. |
||
310 | * |
||
311 | * @return bool True if all rules passed, false if not. |
||
312 | * |
||
313 | */ |
||
314 | 9 | protected function applyToObject($object) |
|
326 | |||
327 | /** |
||
328 | * |
||
329 | * Apply a rule specification to the subject. |
||
330 | * |
||
331 | * @param Spec $spec The rule specification. |
||
332 | * |
||
333 | * @param object $subject The filter subject. |
||
334 | * |
||
335 | * @return bool True to continue, false to stop. |
||
336 | * |
||
337 | */ |
||
338 | 9 | protected function applySpec($spec, $subject) |
|
355 | |||
356 | /** |
||
357 | * |
||
358 | * Adds a failure. |
||
359 | * |
||
360 | * @param Spec $spec The failed rule specification. |
||
361 | * |
||
362 | * @return Failure |
||
363 | * |
||
364 | */ |
||
365 | 7 | protected function failed($spec) |
|
379 | |||
380 | /** |
||
381 | * |
||
382 | * Returns the failures. |
||
383 | * |
||
384 | * @return FailureCollection |
||
385 | * |
||
386 | */ |
||
387 | 6 | public function getFailures() |
|
391 | } |
||
392 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.