1 | <?php |
||
7 | abstract class AbstractValidator implements ValidatorInterface |
||
8 | { |
||
9 | /** |
||
10 | * Input value |
||
11 | * |
||
12 | * @var mixed |
||
13 | */ |
||
14 | protected $value; |
||
15 | |||
16 | /** |
||
17 | * Filter value for valid input value. |
||
18 | * |
||
19 | * @var mixed |
||
20 | */ |
||
21 | protected $standardValue; |
||
22 | |||
23 | /** |
||
24 | * Error messages |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $messages = array(); |
||
29 | |||
30 | /** |
||
31 | * Error message |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $message; |
||
36 | |||
37 | /** |
||
38 | * Error code |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $messageCode; |
||
43 | |||
44 | /** |
||
45 | * Options. |
||
46 | * |
||
47 | * @var array |
||
48 | */ |
||
49 | protected $options = []; |
||
50 | |||
51 | /** |
||
52 | * Default options. |
||
53 | * |
||
54 | * @var array |
||
55 | */ |
||
56 | protected $defaultOptions = []; |
||
57 | |||
58 | /** |
||
59 | * Required options. |
||
60 | * |
||
61 | * @var string[] |
||
62 | */ |
||
63 | protected $requiredOptions = []; |
||
64 | |||
65 | 14 | public function __construct() |
|
69 | |||
70 | /** |
||
71 | * Run validator |
||
72 | * |
||
73 | * @param mixed $value |
||
74 | * |
||
75 | * @return bool |
||
76 | */ |
||
77 | public function __invoke($value) |
||
81 | |||
82 | /** |
||
83 | * Set options. |
||
84 | * |
||
85 | * @param array $options |
||
86 | * |
||
87 | * @return AbstractValidator |
||
88 | */ |
||
89 | 2 | public function setOptions($options) |
|
90 | { |
||
91 | 2 | $this->options = array_merge($this->options, $options); |
|
92 | |||
93 | 2 | return $this; |
|
94 | } |
||
95 | |||
96 | /** |
||
97 | * Get options. |
||
98 | * |
||
99 | * @return array |
||
100 | */ |
||
101 | 2 | public function getOptions() |
|
102 | { |
||
103 | 2 | return $this->options; |
|
104 | } |
||
105 | |||
106 | /** |
||
107 | * Check missing options. |
||
108 | * |
||
109 | * @throws MissingOptionException |
||
110 | */ |
||
111 | 12 | public function checkMissingOptions() |
|
119 | |||
120 | /** |
||
121 | * Reset validator. |
||
122 | * |
||
123 | * @return AbstractValidator |
||
124 | */ |
||
125 | 14 | public function reset() |
|
134 | |||
135 | /** |
||
136 | * Set error. |
||
137 | * |
||
138 | * @param string $code |
||
139 | * |
||
140 | * @return AbstractValidator |
||
141 | */ |
||
142 | 5 | protected function setError($code) |
|
149 | |||
150 | /** |
||
151 | * @inheritdoc |
||
152 | */ |
||
153 | 3 | public function getMessage() |
|
157 | |||
158 | /** |
||
159 | * @inheritdoc |
||
160 | */ |
||
161 | 3 | public function getMessageCode() |
|
165 | |||
166 | /** |
||
167 | * Get standard value |
||
168 | * |
||
169 | * @return mixed |
||
170 | */ |
||
171 | 2 | public function getStandardValue() |
|
172 | { |
||
173 | 2 | return $this->standardValue; |
|
174 | } |
||
175 | |||
176 | /** |
||
177 | * Init method. |
||
178 | */ |
||
179 | 14 | protected function init() |
|
182 | } |
||
183 |