1 | <?php |
||
34 | class AlignedBuilder |
||
35 | { |
||
36 | /** |
||
37 | * The order in which Resource Records should appear in a zone. |
||
38 | * |
||
39 | * @var array |
||
40 | */ |
||
41 | private $order = [ |
||
42 | SOA::TYPE, |
||
43 | NS::TYPE, |
||
44 | A::TYPE, |
||
45 | AAAA::TYPE, |
||
46 | CNAME::TYPE, |
||
47 | DNAME::TYPE, |
||
48 | MX::TYPE, |
||
49 | LOC::TYPE, |
||
50 | HINFO::TYPE, |
||
51 | TXT::TYPE, |
||
52 | PTR::TYPE, |
||
53 | SRV::TYPE, |
||
54 | NSEC3::TYPE, |
||
55 | NSEC3PARAM::TYPE, |
||
56 | RRSIG::TYPE, |
||
57 | ]; |
||
58 | |||
59 | /** |
||
60 | * @var callable[] array of Rdata type indexed, callables that handle the output formatting of Rdata |
||
61 | */ |
||
62 | private $rdataFormatters = []; |
||
63 | |||
64 | 4 | public function __construct() |
|
68 | |||
69 | /** |
||
70 | * Adds or changes an Rdata output formatter. |
||
71 | * |
||
72 | * @param string $type the Rdata type to be handled by the $formatter |
||
73 | * @param callable $formatter callable that will handle the output formatting of the Rdata |
||
74 | */ |
||
75 | public function addRdataFormatter(string $type, callable $formatter): void |
||
79 | |||
80 | public function getRdataFormatters(): array |
||
84 | |||
85 | /** |
||
86 | * @return string[] |
||
87 | */ |
||
88 | public function getOrder(): array |
||
92 | |||
93 | /** |
||
94 | * Set the order in which Resource Records should appear in a zone.. |
||
95 | * |
||
96 | * @param string[] $order Simple string array of Rdata types |
||
97 | */ |
||
98 | public function setOrder(array $order): void |
||
102 | |||
103 | /** |
||
104 | * Build an aligned BIND zone file. |
||
105 | */ |
||
106 | 3 | public function build(Zone $zone): string |
|
140 | |||
141 | /** |
||
142 | * Returns the control entries as strings. |
||
143 | */ |
||
144 | 3 | private static function generateControlEntries(Zone $zone): string |
|
153 | |||
154 | /** |
||
155 | * Returns a comment string if the comments are not null, returns empty string otherwise. |
||
156 | */ |
||
157 | 3 | private static function generateComment(ResourceRecord $resourceRecord): string |
|
165 | |||
166 | /** |
||
167 | * Compares two ResourceRecords to determine which is the higher order. Used with the usort() function. |
||
168 | * |
||
169 | * @param ResourceRecord $a The first ResourceRecord |
||
170 | * @param ResourceRecord $b The second ResourceRecord |
||
171 | * |
||
172 | * @return int $a is higher precedence than $b if return value is less than 0. |
||
173 | * $b is higher precedence than $a if return value is greater than 0. |
||
174 | * $a and $b have the same precedence if the return value is 0. |
||
175 | */ |
||
176 | 4 | public function compareResourceRecords(ResourceRecord $a, ResourceRecord $b): int |
|
208 | |||
209 | /** |
||
210 | * Composes the RDATA of the Resource Record. |
||
211 | * |
||
212 | * @param RdataInterface $rdata the Rdata to be formatted |
||
213 | * @param int $padding the number of spaces before the Rdata column |
||
214 | */ |
||
215 | 3 | private function generateRdataOutput(RdataInterface $rdata, int $padding): string |
|
223 | |||
224 | /** |
||
225 | * Get the padding required for a zone. |
||
226 | * |
||
227 | * @param Zone $zone the DNS Zone being processed |
||
228 | * |
||
229 | * @return int[] Array order: [name, ttl, type, class, rdata] |
||
230 | */ |
||
231 | 3 | private static function getPadding(Zone $zone): array |
|
252 | } |
||
253 |