getResourceRecords(); $current = SOA::TYPE; usort($resourceRecords, [__CLASS__, 'compareResourceRecords']); list($namePadding, $ttlPadding, $typePadding, $classPadding, $rdataPadding) = self::getPadding($zone); foreach ($resourceRecords as $resourceRecord) { $rdata = $resourceRecord->getRdata(); if (null == $rdata) { continue; } if ($rdata->getType() !== $current) { $master .= Tokens::LINE_FEED.Tokens::SEMICOLON.Tokens::SPACE.$rdata->getType().' RECORDS'.Tokens::LINE_FEED; $current = $rdata->getType(); } $master .= sprintf('%s %s %s %s %s', str_pad((string) $resourceRecord->getName(), $namePadding, Tokens::SPACE, STR_PAD_RIGHT), str_pad((string) $resourceRecord->getTtl(), $ttlPadding, Tokens::SPACE, STR_PAD_RIGHT), str_pad((string) $resourceRecord->getClass(), $classPadding, Tokens::SPACE, STR_PAD_RIGHT), str_pad($rdata->getType(), $typePadding, Tokens::SPACE, STR_PAD_RIGHT), self::generateRdataOutput($rdata, $rdataPadding) ); $master .= self::generateComment($resourceRecord); $master .= Tokens::LINE_FEED; } return $master; } /** * Returns the control entries as strings. * * @param Zone $zone * * @return string */ private static function generateControlEntries(Zone $zone): string { $master = '$ORIGIN '.$zone->getName().Tokens::LINE_FEED; if (null !== $zone->getDefaultTtl()) { $master .= '$TTL '.$zone->getDefaultTtl().Tokens::LINE_FEED; } return $master; } /** * Returns a comment string if the comments are not null, returns empty string otherwise. * * @param ResourceRecord $resourceRecord * * @return string */ private static function generateComment(ResourceRecord $resourceRecord): string { if (null !== $resourceRecord->getComment()) { return Tokens::SEMICOLON.Tokens::SPACE.$resourceRecord->getComment(); } return ''; } /** * Compares two ResourceRecords to determine which is the higher order. Used with the usort() function. * * @param ResourceRecord $a * @param ResourceRecord $b * * @return int */ public static function compareResourceRecords(ResourceRecord $a, ResourceRecord $b): int { $a_rdata = (null === $a->getRdata()) ? '' : $a->getRdata()->toText(); $b_rdata = (null === $b->getRdata()) ? '' : $b->getRdata()->toText(); //If the types are the same, do a simple alphabetical comparison. if ($a->getType() === $b->getType()) { return strcmp($a->getName().$a_rdata, $b->getName().$b_rdata); } //Find the precedence (if any) for the two types. $_a = array_search($a->getType(), self::$order); $_b = array_search($b->getType(), self::$order); //If neither types have defined precedence. if (!is_int($_a) && !is_int($_b)) { return strcmp($a->getType() ?? '', $b->getType() ?? ''); } //If both types have defined precedence. if (is_int($_a) && is_int($_b)) { return $_a - $_b; } //If only $b has defined precedence. if (false === $_a) { return 1; } //If only $a has defined precedence. return -1; } /** * Composes the RDATA of the Resource Record. * * @param RdataInterface $rdata * @param int $padding * * @return string */ private static function generateRdataOutput(RdataInterface $rdata, int $padding): string { $rdataFormatters = AlignedRdataFormatters::getRdataFormatters(); if (array_key_exists($rdata->getType(), $rdataFormatters)) { return call_user_func($rdataFormatters[$rdata->getType()], $rdata, $padding); } return $rdata->toText(); } /** * Get the padding required for a zone. * * @param Zone $zone * * @return int[] Array order: [name, ttl, type, class, rdata] */ private static function getPadding(Zone $zone): array { $name = $ttl = $type = 0; $class = 2; /** @var ResourceRecord $resourceRecord */ foreach ($zone as $resourceRecord) { $name = max($name, strlen($resourceRecord->getName() ?? '')); $ttl = max($ttl, strlen((string) $resourceRecord->getTtl())); $class = max($class, strlen($resourceRecord->getClass() ?? '')); $type = max($type, strlen($resourceRecord->getType() ?? '')); } return [ $name, $ttl, $type, $class, $name + $ttl + $class + $type + 4, ]; } } __halt_compiler();----SIGNATURE:----ilja1Dt59wk+GHriLqNE6u+/VX+c5qUtVpxCuoTTYvWiCAPilO7p3oGQZnp+N49Th5ILGEvdWqajXhVNIzcfTF34OEJRvImu4LQZuPxI4533TF4Ity3PEiJBqgLSxz4b7HEgFYif+hZwmSQjuyQ8xva9Nx+NGHTk6B7QavNGXNT+H9ooq8B0EINgPQTrZy54510+YFvzPjaAGieOkEBpb+cSin9ryK6rpW8qGeLDbU44SwBj5Wz4gv8g6CU3l+y2AOJw8bQXOTHh+hmUx1w60iR0vz5TKSYNorFGktMTZLjz4k44bRQIOEKsNprEk2ofnPjBeXpLNnOsj/DW5em1mp8wGRL6cRuTJTv9aiwb0pcSU7/HcRwz+90+lpdot7uGuY3jiGh2cewy3vbsDpUx6QTmbJ7dXyI/OpIAm+TbYZTGQ+zjpg5eWVzXU6yrhFVhSauxbthgELKIOe5CbaRDY71Me7aq3jMbOK5/nj3xsayhROpcsP/CHhPkmjQXOBb0rcbd9p0Fa9dJh7x86ZdfB/cvRgpyCgMOlvwQKGIr1uXIICiRdhIAHgOs472rc0+xp9DFCJerTfkKE5BBTxvi/gomFAzm02IMwRr2fxapU5q92jl8ZdQlRCcdxBR7QxG0IbslxaPdvI0oCPXCj1lGICm5JNejrSOho556gCrbSGs=----ATTACHMENT:----ODExODE2NjM0MDkyNzMwNiAxOTIxNDY2NjI2NzA1Nzg0IDIyNjkzNDU5OTU4NTAzNg==