QueryPath\CSS\DOMTraverser::initialMatch PHP Method

initialMatch() protected method

This should only be executed when not working with an existing match set.
protected initialMatch ( $selector, $matches )
    protected function initialMatch($selector, $matches)
    {
        $element = $selector->element;
        // If no element is specified, we have to start with the
        // entire document.
        if ($element == null) {
            $element = '*';
        }
        // fprintf(STDOUT, "Initial match using %s.\n", $selector);
        // We try to do some optimization here to reduce the
        // number of matches to the bare minimum. This will
        // reduce the subsequent number of operations that
        // must be performed in the query.
        // Experimental: ID queries use XPath to match, since
        // this should give us only a single matched element
        // to work with.
        if (!empty($selector->id)) {
            // fprintf(STDOUT, "ID Fastrack on %s\n", $selector);
            $initialMatches = $this->initialMatchOnID($selector, $matches);
        } elseif (!empty($selector->ns)) {
            $initialMatches = $this->initialMatchOnElementNS($selector, $matches);
        } elseif ($element == '*' && !empty($selector->classes)) {
            // fprintf(STDOUT, "Class Fastrack on %s\n", $selector);
            $initialMatches = $this->initialMatchOnClasses($selector, $matches);
        } else {
            $initialMatches = $this->initialMatchOnElement($selector, $matches);
        }
        //fprintf(STDOUT, "Found %d nodes.\n", count($this->matches));
        return $initialMatches;
    }