Beispiel #1
0
 /**
  * Create a resource record from a Line
  *
  * @param Line $line
  * @return ResourceRecord
  */
 private function lineToRr(Line $line)
 {
     $rr = new ResourceRecord();
     if (null !== ($class = Interpreter::getClassFromLine($line->getData()))) {
         $rr->setClass($class);
     }
     $rr->setRdata($this->getRData($line->getData()));
     $rr->setComment($line->getComment());
     $rr->setName(Interpreter::getResourceNameFromLine($line->getData()));
     return $rr;
 }
    public function testExpand()
    {
        $test_data = <<<TXT
example.com. IN SOA example.com. (
     postmaster.example.com. ; mname
     2013011601              ; the serial number
     10800                   ; Refresh in seconds
     3600                    ; Retry in seconds
     604800                  ; Expire in seconds
     38400 )                 ; Minimum TTL

www IN CNAME example.com ; This is a comment that needs to be stripped
@   A 1800     255.255.255.255; Comments
TXT;
        $expectation = array(array('data' => 'example.com. IN SOA example.com. postmaster.example.com. 2013011601 10800 3600 604800 38400', 'comment' => 'mname the serial number Refresh in seconds Retry in seconds Expire in seconds Minimum TTL'), array('data' => 'www IN CNAME example.com', 'comment' => 'This is a comment that needs to be stripped'), array('data' => '@ A 1800 255.255.255.255', 'comment' => 'Comments'));
        $lines = Interpreter::expand($test_data);
        $this->assertEquals($expectation, $lines);
    }
 /**
  * Parses a data(s) and returns the logic
  * part and comment part
  *
  * @param \ArrayIterator $iterator
  * @return Line
  */
 public static function parseLine(\ArrayIterator $iterator)
 {
     list($line, $comment) = Interpreter::stripCommentFromLine($iterator->current());
     if (strpos($line, '(') !== false) {
         $comment = (array) $comment;
         $flag = true;
         while ($flag) {
             $iterator->next();
             list($_line, $comment[]) = Interpreter::stripCommentFromLine($iterator->current());
             $line .= ' ' . $_line;
             if (strpos($_line, ')') !== false) {
                 $line = trim(preg_replace('/\\s*[\\(\\)]\\s*/', ' ', $line));
                 //Remove the brackets
                 $flag = false;
             }
         }
         $comment = trim(preg_replace('/\\s+/', ' ', implode(' ', $comment)));
     }
     return new Line($line, $comment);
 }