-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
InputFilterInterface.php
185 lines (167 loc) · 5.27 KB
/
InputFilterInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
declare(strict_types=1);
namespace Laminas\InputFilter;
use Countable;
use Laminas\Filter\FilterChain; // phpcs:ignore
use Laminas\Filter\FilterInterface; // phpcs:ignore
use Laminas\Validator\ValidatorChain; // phpcs:ignore
use Laminas\Validator\ValidatorInterface; // phpcs:ignore
use Traversable;
/**
* @psalm-type FilterSpecification = array{
* name: string|class-string<FilterInterface>,
* priority?: int,
* options?: array<string, mixed>,
* }
* @psalm-type ValidatorSpecification = array{
* name: string|class-string<ValidatorInterface>,
* priority?: int,
* break_chain_on_failure?: bool,
* options?: array<string, mixed>,
* }
* @psalm-type InputSpecification = array{
* type?: string|class-string<InputFilterInterface>,
* name?: string,
* required?: bool,
* allow_empty?: bool,
* continue_if_empty?: bool,
* error_message?: string|null,
* fallback_value?: mixed|null,
* break_on_failure?: bool,
* filters?: FilterChain|iterable<array-key, FilterSpecification|callable|FilterInterface>,
* validators?: ValidatorChain|iterable<array-key, ValidatorSpecification|ValidatorInterface>,
* }
* @psalm-type InputFilterSpecification = array{
* type?: class-string<InputFilterInterface>|string,
* }&array<array-key, InputSpecification>
* @psalm-type CollectionSpecification = array{
* type?: class-string<InputFilterInterface>|string,
* input_filter?: InputFilterSpecification|InputFilterInterface,
* count?: int,
* required?: bool,
* required_message?: string,
* }&array<array-key, InputSpecification>
*/
interface InputFilterInterface extends Countable
{
public const VALIDATE_ALL = 'INPUT_FILTER_ALL';
/**
* Add an input to the input filter
*
* @param InputInterface|InputFilterInterface|InputSpecification|Traversable $input
* Implementations MUST handle at least one of the specified types, and
* raise an exception for any they cannot process.
* @param null|string $name Name used to retrieve this input
* @return InputFilterInterface
* @throws Exception\InvalidArgumentException If unable to handle the input type.
*/
public function add($input, $name = null);
/**
* Retrieve a named input
*
* @param string $name
* @return InputInterface|InputFilterInterface
*/
public function get($name);
/**
* Test if an input or input filter by the given name is attached
*
* @param string $name
* @return bool
*/
public function has($name);
/**
* Remove a named input
*
* @param string $name
* @return InputFilterInterface
*/
public function remove($name);
/**
* Set data to use when validating and filtering
*
* @param iterable|null $data
* @return InputFilterInterface
*/
public function setData($data);
/**
* Is the data set valid?
*
* @return bool
*/
public function isValid();
/**
* Provide a list of one or more elements indicating the complete set to validate
*
* When provided, calls to {@link isValid()} will only validate the provided set.
*
* If the initial value is {@link VALIDATE_ALL}, the current validation group, if
* any, should be cleared.
*
* Implementations should allow passing a single array value, or multiple arguments,
* each specifying a single input.
*
* @param string|list<string> $name
* @return InputFilterInterface
*/
public function setValidationGroup($name);
/**
* Return a list of inputs that were invalid.
*
* Implementations should return an associative array of name/input pairs
* that failed validation.
*
* @return array<string, InputInterface|InputFilterInterface>
*/
public function getInvalidInput();
/**
* Return a list of inputs that were valid.
*
* Implementations should return an associative array of name/input pairs
* that passed validation.
*
* @return array<string, InputInterface|InputFilterInterface>
*/
public function getValidInput();
/**
* Retrieve a value from a named input
*
* @param string $name
* @return mixed
*/
public function getValue($name);
/**
* Return a list of filtered values
*
* List should be an associative array, with the values filtered. If
* validation failed, this should raise an exception.
*
* @return array<string, mixed>
*/
public function getValues();
/**
* Retrieve a raw (unfiltered) value from a named input
*
* @param string $name
* @return mixed
*/
public function getRawValue($name);
/**
* Return a list of unfiltered values
*
* List should be an associative array of named input/value pairs,
* with the values unfiltered.
*
* @return array<array-key, mixed>
*/
public function getRawValues();
/**
* Return a list of validation failure messages
*
* Should return an associative array of named input/message list pairs.
* Pairs should only be returned for inputs that failed validation.
*
* @return array<array-key, array<array-key, string>>
*/
public function getMessages();
}