1 | <?php |
||
4 | class FormValidator implements FormValidatorInterface |
||
5 | { |
||
6 | |||
7 | const SUBMITTED = 1; |
||
8 | const VALID = 2; |
||
9 | |||
10 | /** |
||
11 | * Holds status definition |
||
12 | * @var int |
||
13 | */ |
||
14 | protected $flags; |
||
15 | |||
16 | |||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | public $required_fields = array(); |
||
21 | |||
22 | /** |
||
23 | * @var array |
||
24 | */ |
||
25 | public $optional_fields = array(); |
||
26 | |||
27 | |||
28 | /** |
||
29 | * @param array $required Array with field and filter definitions |
||
30 | * @param array $optional Array with field and filter definitions, default: empty array |
||
31 | */ |
||
32 | 6 | public function __construct(array $required, array $optional = array() ) |
|
37 | |||
38 | |||
39 | /** |
||
40 | * @param array $raw_user_input Ususally `$_POST` |
||
41 | * @return array The filtered user input |
||
42 | */ |
||
43 | 6 | public function __invoke( $raw_user_input ) |
|
70 | |||
71 | |||
72 | |||
73 | /** |
||
74 | * @implements FormValidatorInterface |
||
75 | * @return boolean |
||
76 | */ |
||
77 | 6 | public function isSubmitted() |
|
81 | |||
82 | |||
83 | /** |
||
84 | * @implements FormValidatorInterface |
||
85 | * @return boolean |
||
86 | */ |
||
87 | 6 | public function isValid() |
|
91 | |||
92 | |||
93 | |||
94 | 6 | protected function hasFlag($flag) |
|
98 | |||
99 | 6 | protected function setFlag($flag, $value) |
|
108 | |||
109 | public function addRequired( $field, $flag) |
||
115 | |||
116 | public function removeRequired( $field ) |
||
123 | |||
124 | public function addOptional( $field, $flag) |
||
130 | |||
131 | |||
132 | public function removeOptional( $field ) |
||
139 | |||
140 | } |
||
141 |