QueryPath\CSS\DOMTraverser::initialMatchOnClasses PHP Méthode

initialMatchOnClasses() protected méthode

This shortcut should only be used when the initial element is '*' and there are classes set. In any other case, the element finding algo is faster and should be used instead.
protected initialMatchOnClasses ( $selector, $matches )
    protected function initialMatchOnClasses($selector, $matches)
    {
        $found = $this->newMatches();
        $baseQuery = './/*[@class]';
        $xpath = new \DOMXPath($this->dom);
        // Now we try to find any matching IDs.
        foreach ($matches as $node) {
            // Refactor me!
            if ($node->hasAttribute('class')) {
                $intersect = array_intersect($selector->classes, explode(' ', $node->getAttribute('class')));
                if (count($intersect) == count($selector->classes)) {
                    $found->attach($node);
                }
            }
            $nl = $this->initialXpathQuery($xpath, $node, $baseQuery);
            foreach ($nl as $node) {
                $classes = $node->getAttribute('class');
                $classArray = explode(' ', $classes);
                $intersect = array_intersect($selector->classes, $classArray);
                if (count($intersect) == count($selector->classes)) {
                    $found->attach($node);
                }
            }
        }
        // Unset the classes selector.
        $selector->classes = array();
        return $found;
    }