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

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

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

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

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

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

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

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

        return $this;
    }
public function insertBefore ( Node $ node , Node $ newNode ) { $ index = $ this -> indexOf ( $ node ) ; if ( $ index === false ) return $ this -> prepend ( $ newNode ) ; array_splice ( $ this -> children , $ index , 0 , [ $ newNode ] ) ; $ newNode -> parent = $ this ; return $ this ; }
Inserts the second given node before 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]->insertBefore([element:c], [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 before
@param Node $newNode the new node that will be inserted before
the first node

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