string = new StringIterator($zone); $this->commentOptions = $commentOptions; } /** * @throws ParseException */ public static function normalise(string $zone, int $includeComments = Comments::NONE): string { return (new self($zone, $includeComments))->process(); } /** * @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 { if (null === $string = preg_replace('/ {2,}/', Tokens::SPACE, $this->normalisedString)) { throw new \UnexpectedValueException('Unexpected value returned from \preg_replace().'); } $lines = []; foreach (explode(Tokens::LINE_FEED, $string) as $line) { if ('' !== $line = rtrim($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:----nQfb3APfsH6sVsu15hd2HMCoAYC80bUt9JT/f1s+s6hvvQRgU6FUAxxs/nJGmFykM6UaQrLoa7blgTPQFYgJ/U7/1KaW6EeYXcGIlvAtI/ALJ9d6UuKLND1rHBgOtsSsQQA0eJ3Xq80nVQw2W2GaoSO57Fx28mnRznodiu61wLmTiW6MwxDhN0Yvy2egAq/eyPD8I4KvplUz9wthzzA43c+sAOmHAc34/aOjFUMELEVxpgSnjbpxnnRL4x0YZqAaEK4ivLWDa9EpCt5mIHpeVon55XpOQejTRQmpGZKEGxEWrUPuDL9+Gtlbk/lyUmkygNBTAhaGxggvg1TiQ2zB65r33MumSB70SzYZGu8L6DDj6V1MWUNaC6ph5JjKSEHoOIhUEMaE09c2a8rmf3zxCD16d+xMmpzZ8cMktFfOnVjB3aVU2NDqN3ryJbPzaHWhWIfGCDSCSD2JMzc9Rw7Pgg4prqCkQhSdkCOJX4CsJgDURycqz3dkwG1rPNMCeAjufwIxIbDQd4uehOO8b4/s6o3l6P6ytP0jjDXc6f0/j4rXJoVl1+UV2qAimqaVzNzGn52/LAPcXW9xwQd1+aNVxYeraY/mMbLEwa2rY3oCuKqU0tK8oaT2/LiXQtQ6yIWRbmDFfhpjB/WwV6MDYCPgqUFOHUf+iO2Z5EJuwJN/ZBE=----ATTACHMENT:----MzA4MDc5OTE5NDQ3MDc2MCA4MzU1ODI3OTgxNDc5MDI0IDUyMzk2MzM4MzI3MzM3NDc=