Example #1
0
 public function __toString()
 {
     $is_block_tag = !$this->doc->isInlineTag($this->tagName);
     $is_empty_tag = $this->doc->isEmptyTag($this->tagName);
     $open_tag = $this->doc->openTag($this->tagName, $this->attributes);
     $close_tag = $this->doc->closeTag($this->tagName);
     $parts = array();
     array_push($parts, $open_tag);
     if ($is_empty_tag) {
         if (self::$codeFormat && self::$codeFormatIndent == 0) {
             array_push($parts, PHP_EOL);
         }
         return implode('', $parts);
     }
     if (in_array($this->tagName, array('script', 'style'))) {
         if (self::$codeFormat) {
             array_push($parts, PHP_EOL);
         }
         array_push($parts, $this->nodes->rawString());
         if (self::$codeFormat) {
             array_push($parts, PHP_EOL);
         }
         if (self::$codeFormat) {
             array_push($parts, self::indent());
         }
         array_push($parts, $close_tag);
         if (self::$codeFormatIndent == 0) {
             array_push($parts, PHP_EOL);
         }
         return implode('', $parts);
     }
     if (!$this->nodes->isEmpty()) {
         foreach ($this->nodes as $node) {
             self::$codeFormatIndent++;
             if (self::$codeFormat && $is_block_tag) {
                 array_push($parts, PHP_EOL);
             }
             if (self::$codeFormat && $is_block_tag) {
                 array_push($parts, self::indent());
             }
             array_push($parts, TagNodes::escapedString($node));
             self::$codeFormatIndent--;
         }
     }
     if (self::$codeFormat && $is_block_tag) {
         array_push($parts, PHP_EOL);
         array_push($parts, self::indent());
     }
     array_push($parts, $close_tag);
     if (self::$codeFormat && self::$codeFormatIndent == 0) {
         array_push($parts, PHP_EOL);
     }
     return implode('', $parts);
 }