FluidXml\FluidContext::query PHP Method

query() public method

public query ( $query )
    public function query(...$query)
    {
        if (\is_array($query[0])) {
            $query = $query[0];
        }
        $results = [];
        $xp = $this->document->xpath;
        foreach ($this->nodes as $n) {
            foreach ($query as $q) {
                $q = $this->resolveQuery($q);
                // Returns a DOMNodeList.
                $res = $xp->query($q, $n);
                // Algorithm 1:
                // $results = \array_merge($results, \iterator_to_array($res));
                // Algorithm 2:
                // It is faster than \iterator_to_array and a lot faster
                // than \iterator_to_array + \array_merge.
                foreach ($res as $r) {
                    $results[] = $r;
                }
                // Algorithm 3:
                // for ($i = 0, $l = $res->length; $i < $l; ++$i) {
                //         $results[] = $res->item($i);
                // }
            }
        }
        // Performing over multiple sibling nodes a query that ascends
        // the xpath, relative (../..) or absolute (//), returns identical
        // matching results that must be collapsed in an unique result
        // otherwise a subsequent operation is performed multiple times.
        $results = $this->filterQueryResults($results);
        return $this->newContext($results);
    }