QueryPath\DOMQuery::deepestNode PHP Method

deepestNode() protected method

A depth-checking function. Typically, it only needs to be invoked with the first parameter. The rest are used for recursion.
protected deepestNode ( DOMNode $ele, integer $depth, mixed $current = null, DOMNode &$deepest = null ) : array
$ele DOMNode The element.
$depth integer The depth guage
$current mixed The current set.
$deepest DOMNode A reference to the current deepest node.
return array Returns an array of DOM nodes.
    protected function deepestNode(\DOMNode $ele, $depth = 0, $current = null, &$deepest = null)
    {
        // FIXME: Should this use SplObjectStorage?
        if (!isset($current)) {
            $current = array($ele);
        }
        if (!isset($deepest)) {
            $deepest = $depth;
        }
        if ($ele->hasChildNodes()) {
            foreach ($ele->childNodes as $child) {
                if ($child->nodeType === XML_ELEMENT_NODE) {
                    $current = $this->deepestNode($child, $depth + 1, $current, $deepest);
                }
            }
        } elseif ($depth > $deepest) {
            $current = array($ele);
            $deepest = $depth;
        } elseif ($depth === $deepest) {
            $current[] = $ele;
        }
        return $current;
    }