Exemple #1
0
 /**
  * Dump tag node.
  *
  * @param   TagNode $node   tag node
  * @param   integer $level  indentation level
  *
  * @return  string
  */
 protected function dumpTag(TagNode $node, $level = 0)
 {
     $html = str_repeat('  ', $level);
     if (in_array($node->getName(), $this->selfClosing)) {
         $html .= '<' . $node->getName();
         $html .= $this->dumpAttributes($node->getAttributes());
         $html .= ' />';
         return $html;
     } else {
         if (count($node->getAttributes())) {
             $html .= '<' . $node->getName();
             $html .= $this->dumpAttributes($node->getAttributes());
             $html .= '>';
         } else {
             $html .= '<' . $node->getName() . '>';
         }
         if ($node->getCode()) {
             if (count($node->getChildren())) {
                 $html .= "\n" . str_repeat('  ', $level + 1) . $this->dumpCode($node->getCode());
             } else {
                 $html .= $this->dumpCode($node->getCode());
             }
         }
         if ($node->getText() && count($node->getText()->getLines())) {
             if (count($node->getChildren())) {
                 $html .= "\n" . str_repeat('  ', $level + 1) . $this->dumpText($node->getText());
             } else {
                 $html .= $this->dumpText($node->getText());
             }
         }
         if (count($node->getChildren())) {
             $html .= "\n";
             $children = $node->getChildren();
             foreach ($children as $i => $child) {
                 $this->nextIsIf[$level + 1] = isset($children[$i + 1]) && $children[$i + 1] instanceof CodeNode;
                 $html .= $this->dumpNode($child, $level + 1);
             }
             $html .= "\n" . str_repeat('  ', $level);
         }
         return $html . '</' . $node->getName() . '>';
     }
 }