Пример #1
0
 public function splitUntil(TagNode $parent, Node $split, $includeLeft)
 {
     $splitOccured = false;
     if ($parent !== $this) {
         $part1 = new TagNode(null, $this->qName, $this->attributes);
         $part2 = new TagNode(null, $this->qName, $this->attributes);
         $part1->setParent($this->parent);
         $part2->setParent($this->parent);
         $onSplit = false;
         $pastSplit = false;
         foreach ($this->children as &$child) {
             if ($child === $split) {
                 $onSplit = true;
             }
             if (!$pastSplit || $onSplit && $includeLeft) {
                 $child->setParent($part1);
                 $part1->children[] = $child;
             } else {
                 $child->setParent($part2);
                 $part2->children[] = $child;
             }
             if ($onSplit) {
                 $onSplit = false;
                 $pastSplit = true;
             }
         }
         $myindexinparent = $this->parent->getIndexOf($this);
         if (!empty($part2->children)) {
             $this->parent->addChildAbsolute($part2, $myindexinparent + 1);
         }
         if (!empty($part1->children)) {
             $this->parent->addChildAbsolute($part1, $myindexinparent + 1);
         }
         if (!empty($part1->children) && !empty($part2->children)) {
             $splitOccured = true;
         }
         $this->parent->removeChild($myindexinparent);
         if ($includeLeft) {
             $this->parent->splitUntil($parent, $part1, $includeLeft);
         } else {
             $this->parent->splitUntil($parent, $part2, $includeLeft);
         }
     }
     return $splitOccured;
 }
Пример #2
0
 public function splitUntil(TagNode $parent, Node $split, $includeLeft)
 {
     $splitOccured = false;
     if ($parent !== $this) {
         $part1 = new TagNode(null, $this->qName, $this->attributes);
         $part2 = new TagNode(null, $this->qName, $this->attributes);
         $part1->setParent($this->parent);
         $part2->setParent($this->parent);
         $onSplit = false;
         $pastSplit = false;
         foreach ($this->children as &$child) {
             if ($child === $split) {
                 $onSplit = true;
             }
             if (!$pastSplit || $onSplit && $includeLeft) {
                 $child->setParent($part1);
                 $part1->children[] = $child;
             } else {
                 $child->setParent($part2);
                 $part2->children[] = $child;
             }
             if ($onSplit) {
                 $onSplit = false;
                 $pastSplit = true;
             }
         }
         // Replace the existing child with $part1 (left) and $part2 (right).
         // Insertions shift existing content right, so insert part2 before
         // inserting part1.
         $myindexinparent = $this->parent->getIndexOf($this);
         $this->parent->removeChild($myindexinparent);
         if (!empty($part2->children)) {
             $this->parent->addChildAbsolute($part2, $myindexinparent);
         }
         if (!empty($part1->children)) {
             $this->parent->addChildAbsolute($part1, $myindexinparent);
         }
         if (!empty($part1->children) && !empty($part2->children)) {
             $splitOccured = true;
         }
         if ($includeLeft) {
             $this->parent->splitUntil($parent, $part1, $includeLeft);
         } else {
             $this->parent->splitUntil($parent, $part2, $includeLeft);
         }
     }
     return $splitOccured;
 }