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 | * @param string $name |
||
39 | * |
||
40 | * @return bool |
||
41 | */ |
||
42 | 1 | public static function hostName(string $name): bool |
|
46 | |||
47 | /** |
||
48 | * Validate the string is a Fully Qualified Domain Name. |
||
49 | * |
||
50 | * @param string $name |
||
51 | * |
||
52 | * @return bool |
||
53 | */ |
||
54 | 63 | public static function fullyQualifiedDomainName(string $name): bool |
|
63 | |||
64 | /** |
||
65 | * Validate the name for a Resource Record. This is distinct from validating a hostname in that this function |
||
66 | * will permit '@' and wildcards as well as underscores used in SRV records. |
||
67 | * |
||
68 | * @param string $name |
||
69 | * |
||
70 | * @return bool |
||
71 | */ |
||
72 | 3 | public static function resourceRecordName(string $name): bool |
|
77 | |||
78 | /** |
||
79 | * Validates an IPv4 Address. |
||
80 | * |
||
81 | * @static |
||
82 | * |
||
83 | * @param string $address |
||
84 | * |
||
85 | * @return bool |
||
86 | */ |
||
87 | 21 | public static function ipv4(string $address): bool |
|
93 | |||
94 | /** |
||
95 | * Validates an IPv6 Address. |
||
96 | * |
||
97 | * @static |
||
98 | * |
||
99 | * @param string $address |
||
100 | * |
||
101 | * @return bool |
||
102 | */ |
||
103 | 34 | public static function ipv6(string $address): bool |
|
109 | |||
110 | /** |
||
111 | * Validates an IPv4 or IPv6 address. |
||
112 | * |
||
113 | * @static |
||
114 | * |
||
115 | * @param string $address |
||
116 | * |
||
117 | * @return bool |
||
118 | */ |
||
119 | 1 | public static function ipAddress(string $address): bool |
|
123 | |||
124 | /** |
||
125 | * Validates that the zone meets |
||
126 | * RFC-1035 especially that: |
||
127 | * 1) 5.2.1 All RRs in the file should be of the same class. |
||
128 | * 2) 5.2.2 Exactly one SOA RR should be present at the top of the zone. |
||
129 | * 3) There is at least one NS record. |
||
130 | * |
||
131 | * Return values are: |
||
132 | * - ZONE_NO_SOA |
||
133 | * - ZONE_TOO_MANY_SOA |
||
134 | * - ZONE_NO_NS |
||
135 | * - ZONE_NO_CLASS |
||
136 | * - ZONE_TOO_MANY_CLASSES |
||
137 | * - ZONE_OKAY |
||
138 | * |
||
139 | * You SHOULD compare these return values to the defined constants of this |
||
140 | * class rather than against integers directly. |
||
141 | * |
||
142 | * @param Zone $zone |
||
143 | * |
||
144 | * @return int |
||
145 | */ |
||
146 | 4 | public static function zone(Zone $zone): int |
|
166 | |||
167 | /** |
||
168 | * Counts the number of Resource Records of a particular type ($type) in a Zone. |
||
169 | * |
||
170 | * @param Zone $zone |
||
171 | * @param string $type The ResourceRecord type to be counted. If NULL, then the method will return |
||
172 | * the number of records without RData. |
||
173 | * |
||
174 | * @return int the number of records to be counted |
||
175 | */ |
||
176 | 4 | public static function countResourceRecords(Zone $zone, ?string $type = null): int |
|
185 | |||
186 | /** |
||
187 | * Validates a reverse IPv4 address. Ensures that all octets are in the range [0-255]. |
||
188 | * |
||
189 | * @param string $address |
||
190 | * |
||
191 | * @return bool |
||
192 | */ |
||
193 | 1 | public static function reverseIpv4(string $address): bool |
|
212 | |||
213 | /** |
||
214 | * Validates a reverse IPv6 address. |
||
215 | * |
||
216 | * @param string $address |
||
217 | * |
||
218 | * @return bool |
||
219 | */ |
||
220 | 1 | public static function reverseIpv6(string $address): bool |
|
226 | |||
227 | /** |
||
228 | * Determine the number of unique non-null classes in a Zone. In a valid zone this MUST be 1. |
||
229 | * |
||
230 | * @param Zone $zone |
||
231 | * |
||
232 | * @return int |
||
233 | */ |
||
234 | 4 | private static function countClasses(Zone $zone): int |
|
246 | |||
247 | /** |
||
248 | * Ensure $zone does not contain existing CNAME alias corresponding to $newRecord's name. |
||
249 | * |
||
250 | * E.g. |
||
251 | * www IN CNAME example.com. |
||
252 | * www IN TXT "This is a violation of DNS specifications." |
||
253 | * |
||
254 | * @see https://tools.ietf.org/html/rfc1034#section-3.6.2 |
||
255 | * |
||
256 | * @param Zone $zone |
||
257 | * @param ResourceRecord $newRecord |
||
258 | * |
||
259 | * @return bool |
||
260 | */ |
||
261 | 1 | public static function noAliasInZone(Zone $zone, ResourceRecord $newRecord): bool |
|
272 | |||
273 | /** |
||
274 | * Determine if string is a base64 encoded string. |
||
275 | * |
||
276 | * @param string $string A base64 encoded string |
||
277 | * |
||
278 | * @return bool |
||
279 | */ |
||
280 | 24 | public static function isBase64Encoded(string $string): bool |
|
296 | |||
297 | /** |
||
298 | * Determine if $integer is an unsigned integer less than 2^$numberOfBits. |
||
299 | * |
||
300 | * @param int $integer The integer to test |
||
301 | * @param int $numberOfBits The upper limit that the integer can be expressed as an exponent of 2 |
||
302 | * |
||
303 | * @return bool |
||
304 | */ |
||
305 | 36 | public static function isUnsignedInteger(int $integer, int $numberOfBits): bool |
|
315 | } |
||
316 |