1 | <?php |
||
17 | class Validator |
||
18 | { |
||
19 | const ZONE_OKAY = 0; |
||
20 | |||
21 | const ZONE_NO_SOA = 1; |
||
22 | |||
23 | const ZONE_TOO_MANY_SOA = 2; |
||
24 | |||
25 | const ZONE_NO_NS = 4; |
||
26 | |||
27 | const ZONE_NO_CLASS = 8; |
||
28 | |||
29 | const ZONE_TOO_MANY_CLASSES = 16; |
||
30 | |||
31 | /** |
||
32 | * Validate the string as a valid hostname in accordance with RFC 952 {@link https://tools.ietf.org/html/rfc952} |
||
33 | * and RFC 1123 {@link https://tools.ietf.org/html/rfc1123}. |
||
34 | * |
||
35 | * @param string $name |
||
36 | * |
||
37 | * @return bool |
||
38 | */ |
||
39 | public static function hostName(string $name): bool |
||
43 | |||
44 | /** |
||
45 | * Validate the string is a Fully Qualified Domain Name. |
||
46 | * |
||
47 | * @param string $name |
||
48 | * |
||
49 | * @return bool |
||
50 | */ |
||
51 | public static function fullyQualifiedDomainName(string $name): bool |
||
86 | |||
87 | /** |
||
88 | * Validate the name for a Resource Record. This is distinct from validating a hostname in that this function |
||
89 | * will permit '@' and wildcards as well as underscores used in SRV records. |
||
90 | * |
||
91 | * @param string $name |
||
92 | * |
||
93 | * @return bool |
||
94 | */ |
||
95 | public static function resourceRecordName(string $name): bool |
||
139 | |||
140 | /** |
||
141 | * Validates an IPv4 Address. |
||
142 | * |
||
143 | * @static |
||
144 | * |
||
145 | * @param string $address |
||
146 | * |
||
147 | * @return bool |
||
148 | */ |
||
149 | public static function ipv4(string $address): bool |
||
155 | |||
156 | /** |
||
157 | * Validates an IPv6 Address. |
||
158 | * |
||
159 | * @static |
||
160 | * |
||
161 | * @param string $address |
||
162 | * |
||
163 | * @return bool |
||
164 | */ |
||
165 | public static function ipv6(string $address): bool |
||
171 | |||
172 | /** |
||
173 | * Validates an IPv4 or IPv6 address. |
||
174 | * |
||
175 | * @static |
||
176 | * |
||
177 | * @param $address |
||
178 | * |
||
179 | * @return bool |
||
180 | */ |
||
181 | public static function ipAddress(string $address): bool |
||
185 | |||
186 | /** |
||
187 | * Validates that the zone meets |
||
188 | * RFC-1035 especially that: |
||
189 | * 1) 5.2.1 All RRs in the file should be of the same class. |
||
190 | * 2) 5.2.2 Exactly one SOA RR should be present at the top of the zone. |
||
191 | * 3) There is at least one NS record. |
||
192 | * |
||
193 | * Return values are: |
||
194 | * - ZONE_NO_SOA |
||
195 | * - ZONE_TOO_MANY_SOA |
||
196 | * - ZONE_NO_NS |
||
197 | * - ZONE_NO_CLASS |
||
198 | * - ZONE_TOO_MANY_CLASSES |
||
199 | * - ZONE_OKAY |
||
200 | * |
||
201 | * You SHOULD compare these return values to the defined constants of this |
||
202 | * class rather than against integers directly. |
||
203 | * |
||
204 | * @param Zone $zone |
||
205 | * |
||
206 | * @return int |
||
207 | */ |
||
208 | public static function zone(Zone $zone): int |
||
245 | |||
246 | /** |
||
247 | * Counts the number of Resource Records of a particular type ($type) in a Zone. |
||
248 | * |
||
249 | * @param Zone $zone |
||
250 | * @param string $type The ResourceRecord type to be counted. If NULL, then the method will return |
||
251 | * the number of records without RData. |
||
252 | * |
||
253 | * @return int the number of records to be counted |
||
254 | */ |
||
255 | public static function countResourceRecords(Zone $zone, ?string $type = null): int |
||
264 | |||
265 | /** |
||
266 | * Validates a reverse IPv4 address. Ensures that all octets are in the range [0-255]. |
||
267 | * |
||
268 | * @param string $address |
||
269 | * |
||
270 | * @return bool |
||
271 | */ |
||
272 | public static function reverseIpv4(string $address): bool |
||
291 | |||
292 | /** |
||
293 | * Validates a reverse IPv6 address. |
||
294 | * |
||
295 | * @param string $address |
||
296 | * |
||
297 | * @return bool |
||
298 | */ |
||
299 | public static function reverseIpv6(string $address): bool |
||
305 | } |
||
306 |