1 | <?php |
||
20 | class Validator |
||
21 | { |
||
22 | const ZONE_OKAY = 0; |
||
23 | |||
24 | const ZONE_NO_SOA = 1; |
||
25 | |||
26 | const ZONE_TOO_MANY_SOA = 2; |
||
27 | |||
28 | const ZONE_NO_NS = 4; |
||
29 | |||
30 | const ZONE_NO_CLASS = 8; |
||
31 | |||
32 | const ZONE_TOO_MANY_CLASSES = 16; |
||
33 | |||
34 | /** |
||
35 | * Validate the string as a valid hostname in accordance with RFC 952 {@link https://tools.ietf.org/html/rfc952} |
||
36 | * and RFC 1123 {@link https://tools.ietf.org/html/rfc1123}. |
||
37 | */ |
||
38 | 112 | public static function hostName(string $name): bool |
|
44 | |||
45 | /** |
||
46 | * Validate the string is a Fully Qualified Domain Name. |
||
47 | */ |
||
48 | 114 | public static function fullyQualifiedDomainName(string $name): bool |
|
56 | |||
57 | /** |
||
58 | * Validate the name for a Resource Record. This is distinct from validating a hostname in that this function |
||
59 | * will permit '@' and wildcards as well as underscores used in SRV records. |
||
60 | */ |
||
61 | 44 | public static function resourceRecordName(string $name): bool |
|
66 | |||
67 | /** |
||
68 | * Validates an IPv4 Address. |
||
69 | * |
||
70 | * @static |
||
71 | */ |
||
72 | 70 | public static function ipv4(string $address): bool |
|
78 | |||
79 | /** |
||
80 | * Validates an IPv6 Address. |
||
81 | * |
||
82 | * @static |
||
83 | */ |
||
84 | 67 | public static function ipv6(string $address): bool |
|
90 | |||
91 | /** |
||
92 | * Validates an IPv4 or IPv6 address. |
||
93 | * |
||
94 | * @static |
||
95 | */ |
||
96 | 12 | public static function ipAddress(string $address): bool |
|
100 | |||
101 | /** |
||
102 | * Validates that the zone meets |
||
103 | * RFC-1035 especially that: |
||
104 | * 1) 5.2.1 All RRs in the file should be of the same class. |
||
105 | * 2) 5.2.2 Exactly one SOA RR should be present at the top of the zone. |
||
106 | * 3) There is at least one NS record. |
||
107 | * |
||
108 | * Return values are: |
||
109 | * - ZONE_NO_SOA |
||
110 | * - ZONE_TOO_MANY_SOA |
||
111 | * - ZONE_NO_NS |
||
112 | * - ZONE_NO_CLASS |
||
113 | * - ZONE_TOO_MANY_CLASSES |
||
114 | * - ZONE_OKAY |
||
115 | * |
||
116 | * You SHOULD compare these return values to the defined constants of this |
||
117 | * class rather than against integers directly. |
||
118 | */ |
||
119 | 4 | public static function zone(Zone $zone): int |
|
139 | |||
140 | /** |
||
141 | * Counts the number of Resource Records of a particular type ($type) in a Zone. |
||
142 | * |
||
143 | * @param string $type The ResourceRecord type to be counted. If NULL, then the method will return |
||
144 | * the number of records without RData. |
||
145 | * |
||
146 | * @return int the number of records to be counted |
||
147 | */ |
||
148 | 4 | public static function countResourceRecords(Zone $zone, ?string $type = null): int |
|
157 | |||
158 | /** |
||
159 | * Validates a reverse IPv4 address. Ensures that all octets are in the range [0-255]. |
||
160 | */ |
||
161 | 15 | public static function reverseIpv4(string $address): bool |
|
180 | |||
181 | /** |
||
182 | * Validates a reverse IPv6 address. |
||
183 | */ |
||
184 | 3 | public static function reverseIpv6(string $address): bool |
|
190 | |||
191 | /** |
||
192 | * Determine the number of unique non-null classes in a Zone. In a valid zone this MUST be 1. |
||
193 | */ |
||
194 | 4 | private static function countClasses(Zone $zone): int |
|
206 | |||
207 | /** |
||
208 | * Ensure $zone does not contain existing CNAME alias corresponding to $newRecord's name. |
||
209 | * |
||
210 | * E.g. |
||
211 | * www IN CNAME example.com. |
||
212 | * www IN TXT "This is a violation of DNS specifications." |
||
213 | * |
||
214 | * @see https://tools.ietf.org/html/rfc1034#section-3.6.2 |
||
215 | */ |
||
216 | 1 | public static function noAliasInZone(Zone $zone, ResourceRecord $newRecord): bool |
|
227 | |||
228 | /** |
||
229 | * Determine if string is a base64 encoded string. |
||
230 | * |
||
231 | * @param string $string A base64 encoded string |
||
232 | */ |
||
233 | 1 | public static function isBase64Encoded(string $string): bool |
|
249 | |||
250 | /** |
||
251 | * Determine if string is a base32 encoded string. |
||
252 | */ |
||
253 | 1 | public static function isBase32Encoded(string $string): bool |
|
257 | |||
258 | /** |
||
259 | * Determine if string is a base32hex (extended hex) encoded string. |
||
260 | */ |
||
261 | public static function isBase32HexEncoded(string $string): bool |
||
265 | |||
266 | /** |
||
267 | * Determine if string is a base16 encoded string. |
||
268 | */ |
||
269 | public static function isBase16Encoded(string $string): bool |
||
273 | |||
274 | /** |
||
275 | * Determine if $integer is an unsigned integer less than 2^$numberOfBits. |
||
276 | * |
||
277 | * @param int $integer The integer to test |
||
278 | * @param int $numberOfBits The upper limit that the integer can be expressed as an exponent of 2 |
||
279 | */ |
||
280 | 122 | public static function isUnsignedInteger(int $integer, int $numberOfBits): bool |
|
290 | } |
||
291 |