string = new StringIterator($zone); $this->commentOptions = $commentOptions; } /** * @param string $zone * @param int $includeComments * * @return string * * @throws ParseException */ public static function normalise(string $zone, int $includeComments = Comments::NONE): string { return (new self($zone, $includeComments))->process(); } /** * @return string * * @throws ParseException */ public function process(): string { while ($this->string->valid()) { $this->handleTxt(); $this->handleMultiline(); $this->handleComment(Comments::END_OF_ENTRY | Comments::ORPHAN); $this->append(); } $this->removeWhitespace(); return $this->normalisedString; } /** * Parses the comments. * * @param int $condition */ private function handleComment($condition = Comments::ALL): void { if ($this->string->isNot(Tokens::SEMICOLON)) { return; } $this->string->next(); while ($this->string->isNot(Tokens::LINE_FEED) && $this->string->valid()) { if ($this->commentOptions & $condition) { if ($condition & Comments::MULTILINE) { $this->multilineComments .= $this->string->current(); } else { $this->comment .= $this->string->current(); } } $this->string->next(); } } /** * Handle text inside of double quotations. When this function is called, the String pointer MUST be at the * double quotation mark. * * @throws ParseException */ private function handleTxt(): void { if ($this->string->isNot(Tokens::DOUBLE_QUOTES)) { return; } $this->append(); while ($this->string->isNot(Tokens::DOUBLE_QUOTES)) { if (!$this->string->valid()) { throw new ParseException('Unbalanced double quotation marks. End of file reached.'); } //If escape character if ($this->string->is(Tokens::BACKSLASH)) { $this->append(); } if ($this->string->is(Tokens::LINE_FEED)) { throw new ParseException('Line Feed found within double quotation marks context.', $this->string); } $this->append(); } } /** * Move multi-line records onto single line. * * @throws ParseException */ private function handleMultiline(): void { if ($this->string->isNot(Tokens::OPEN_BRACKET)) { return; } $this->string->next(); while ($this->string->valid()) { $this->handleTxt(); $this->handleComment(Comments::MULTILINE); if ($this->string->is(Tokens::LINE_FEED)) { $this->string->next(); continue; } if ($this->string->is(Tokens::CLOSE_BRACKET)) { $this->string->next(); $this->process(); return; } $this->append(); } throw new ParseException('End of file reached. Unclosed bracket.'); } /** * Remove superfluous whitespace characters from string. * * @throws \UnexpectedValueException */ private function removeWhitespace(): void { $string = preg_replace('/ {2,}/', Tokens::SPACE, $this->normalisedString); if (!is_string($string)) { throw new \UnexpectedValueException('Unexpected value returned from \preg_replace()/.'); } $lines = []; foreach (explode(Tokens::LINE_FEED, $string) as $line) { if ('' !== $line = trim($line)) { $lines[] = $line; } } $this->normalisedString = implode(Tokens::LINE_FEED, $lines); } /** * Add current entry to normalisedString and moves iterator to next entry. */ private function append(): void { if (($this->string->is(Tokens::LINE_FEED) || !$this->string->valid()) && $this->commentOptions && ('' !== $this->comment || '' !== $this->multilineComments)) { $this->appendComment(); } $this->normalisedString .= $this->string->current(); $this->string->next(); } private function appendComment(): void { $zone = rtrim($this->normalisedString, Tokens::SPACE); //If there is no Resource Record on the line if ((Tokens::LINE_FEED === substr($zone, -1, 1) || 0 === strlen($zone))) { if ($this->commentOptions & Comments::ORPHAN) { $this->normalisedString = sprintf('%s;%s', $zone, trim($this->comment)); } $this->comment = ''; $this->multilineComments = ''; return; } $comments = ''; if (($this->commentOptions & Comments::MULTILINE) && '' !== $this->multilineComments) { $comments .= $this->multilineComments; } if (($this->commentOptions & Comments::END_OF_ENTRY) && '' !== $this->comment) { $comments .= $this->comment; } if ('' !== $comments = trim($comments)) { $this->normalisedString = sprintf('%s;%s', $zone, $comments); } $this->comment = ''; $this->multilineComments = ''; } } __halt_compiler();----SIGNATURE:----jjnB5xpgTBQ3WyT4s2Z161sBjNxNcoKKuo5YoPE/MJ8TRdmyOmQE5uB3LO71gpytt0bT4NxIstazY/dIgusrKPXW07jViBlnbgG5uZCaOHTU+5ZKRynsToBKPAsjv8uAALTqCloOZGCleC5+gFbyovzlKwWaq/t7lxsZJmBV8T8XRC81Va9zPRwsHh3dWwKlTUvOlHZZoCUnzC2Nd9x4elTrV5dE8j3MHS6HDvgyFoC1UrqDCLZDJj2h7A7YWvXFmbif9NMq8LBKyOtM+5AzzINwhscSHo3V2R/WX2KSGH79tJoOWbxEDYpnGoxm3mYXqd9ZKKoSHws+Mymkcm3HWCTyVqLQMMdPC06dTNi0Bww4TZdq4DDV1oAwoeG847Z8q1GZao1N1iyCFSmQqAzQba66K7vWJOh6xZ4WGQLaO96g0H8N7OHIresofC8RbY5d82RPiM4Rl7wYke/EWa0hqzyBE+B2YM3ViXXc1s3TGvFNdayqwA350ChJ7p8dP/LFbXYlkIT3I4KCpXJzOxOEZUodbt81hurqzSFfuv3pA1dc4pRqagy929FAC/F5S6w6P+t7+aHqJzjRAlDT+U6u5yd256RQrcBFg8tjIEOGYvVYufbVJY+m/8zrKMV/JwO2FJpkSQDvSUGo9r5XzrTHUx2ExTU0vAju1ayxGEbeRZo=----ATTACHMENT:----OTYzMTU3MzU4MTM4MzAxNiA0OTI2NTc5ODQ1MDY5OTA3IDkxNDAyNTA5MDU4Njg0MjQ=