Пример #1
0
 public function addChild($level, NodeAbstract $node)
 {
     $this->updateStack($level);
     if (!$this->parent instanceof NestInterface) {
         $parent = $this->parent;
         if ($parent instanceof Statement) {
             $parent = $parent->getContent();
         }
         $msg = sprintf('Illegal nesting: nesting within %s is illegal', $parent->getNodeName());
         throw new TreeBuilderException($msg);
     }
     if ($this->parent->hasContent() && !$this->parent->allowsNestingAndContent()) {
         if ($this->parent instanceof Tag) {
             $msg = sprintf('Illegal nesting: content can\'t be both given on the same line as %%%s and nested within it', $this->parent->getTagName());
         } else {
             $msg = sprintf('Illegal nesting: nesting within a tag that already has content is illegal');
         }
         throw new TreeBuilderException($msg);
     }
     if ($this->parent instanceof Tag && $this->parent->getFlags() & Tag::FLAG_SELF_CLOSE) {
         $msg = 'Illegal nesting: nesting within a self-closing tag is illegal';
         throw new TreeBuilderException($msg);
     }
     $this->parent->addChild($node);
     $this->prev = $node;
 }
 protected function shouldIndentBeforeClose(NodeAbstract $node)
 {
     if ($node instanceof Tag) {
         if ($node->getFlags() & Tag::FLAG_REMOVE_INNER_WHITESPACES) {
             return false;
         }
         if (!$node->hasChilds()) {
             return false;
         }
     }
     if (null !== ($child = $this->getLastChildIfTag($node))) {
         if ($child->getFlags() & Tag::FLAG_REMOVE_OUTER_WHITESPACES) {
             return false;
         }
     }
     return true;
 }