Parser/Node.php
public function insertAfter(Node $node, Node $newNode)
    {

        $index = $this->indexOf($node);

        if ($index === false)
            return $this->append($newNode);

        array_splice($this->children, $index + 1, 0, [$newNode]);
        $newNode->parent = $this;

        return $this;
    }
public function insertAfter(Node $node, Node $newNode)
    {

        $index = $this->indexOf($node);

        if ($index === false)
            return $this->append($newNode);

        array_splice($this->children, $index + 1, 0, [$newNode]);
        $newNode->parent = $this;

        return $this;
    }
public function insertAfter ( Node $ node , Node $ newNode ) { $ index = $ this -> indexOf ( $ node ) ; if ( $ index === false ) return $ this -> append ( $ newNode ) ; array_splice ( $ this -> children , $ index + 1 , 0 , [ $ newNode ] ) ; $ newNode -> parent = $ this ; return $ this ; }
Inserts the second given node after the first given node
inside this node's children.

This allows fine control over the node's children

The new nodes parent will be set to this node

[element:a]
(0)[element:b]
(1)[element:c]

[element:a]->insertAfter([element:b], [element:d])

[element:a]
(0)[element:b]
(1)[element:d]
(2)[element:c]

@param Node $node    the child node of this node's children the new
node will be inserted after
@param Node $newNode the new node that will be inserted after the
first node

@return $this
Inserts the second given node after the first given node inside this node s children .