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 | 1 | 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 | 3 | public static function fullyQualifiedDomainName(string $name): bool |
|
82 | |||
83 | /** |
||
84 | * Validate the name for a Resource Record. This is distinct from validating a hostname in that this function |
||
85 | * will permit '@' and wildcards as well as underscores used in SRV records. |
||
86 | * |
||
87 | * @param string $name |
||
88 | * |
||
89 | * @return bool |
||
90 | */ |
||
91 | 3 | public static function resourceRecordName(string $name): bool |
|
133 | |||
134 | /** |
||
135 | * Validates an IPv4 Address. |
||
136 | * |
||
137 | * @static |
||
138 | * |
||
139 | * @param string $address |
||
140 | * |
||
141 | * @return bool |
||
142 | */ |
||
143 | 1 | public static function ipv4(string $address): bool |
|
149 | |||
150 | /** |
||
151 | * Validates an IPv6 Address. |
||
152 | * |
||
153 | * @static |
||
154 | * |
||
155 | * @param string $address |
||
156 | * |
||
157 | * @return bool |
||
158 | */ |
||
159 | 5 | public static function ipv6(string $address): bool |
|
165 | |||
166 | /** |
||
167 | * Validates an IPv4 or IPv6 address. |
||
168 | * |
||
169 | * @static |
||
170 | * |
||
171 | * @param $address |
||
172 | * |
||
173 | * @return bool |
||
174 | */ |
||
175 | 1 | public static function ipAddress(string $address): bool |
|
179 | |||
180 | /** |
||
181 | * Validates that the zone meets |
||
182 | * RFC-1035 especially that: |
||
183 | * 1) 5.2.1 All RRs in the file should be of the same class. |
||
184 | * 2) 5.2.2 Exactly one SOA RR should be present at the top of the zone. |
||
185 | * 3) There is at least one NS record. |
||
186 | * |
||
187 | * Return values are: |
||
188 | * - ZONE_NO_SOA |
||
189 | * - ZONE_TOO_MANY_SOA |
||
190 | * - ZONE_NO_NS |
||
191 | * - ZONE_NO_CLASS |
||
192 | * - ZONE_TOO_MANY_CLASSES |
||
193 | * - ZONE_OKAY |
||
194 | * |
||
195 | * You SHOULD compare these return values to the defined constants of this |
||
196 | * class rather than against integers directly. |
||
197 | * |
||
198 | * @param Zone $zone |
||
199 | * |
||
200 | * @return int |
||
201 | */ |
||
202 | 4 | public static function zone(Zone $zone): int |
|
229 | |||
230 | /** |
||
231 | * Counts the number of Resource Records of a particular type ($type) in a Zone. |
||
232 | * |
||
233 | * @param Zone $zone |
||
234 | * @param string $type The ResourceRecord type to be counted. If NULL, then the method will return |
||
235 | * the number of records without RData. |
||
236 | * |
||
237 | * @return int the number of records to be counted |
||
238 | */ |
||
239 | 4 | public static function countResourceRecords(Zone $zone, ?string $type = null): int |
|
248 | |||
249 | /** |
||
250 | * Validates a reverse IPv4 address. Ensures that all octets are in the range [0-255]. |
||
251 | * |
||
252 | * @param string $address |
||
253 | * |
||
254 | * @return bool |
||
255 | */ |
||
256 | 1 | public static function reverseIpv4(string $address): bool |
|
275 | |||
276 | /** |
||
277 | * Validates a reverse IPv6 address. |
||
278 | * |
||
279 | * @param string $address |
||
280 | * |
||
281 | * @return bool |
||
282 | */ |
||
283 | 1 | public static function reverseIpv6(string $address): bool |
|
289 | } |
||
290 |