Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Combinator.php

function Combinator::exec

Executes the current group on the given matches

Parameters

Matches $matches Matches:

File

vendor/mck89/peast/lib/Peast/Selector/Node/Combinator.php, line 66

Class

Combinator
Selector combinator class

Namespace

Peast\Selector\Node

Code

public function exec(Matches $matches) {
    $parts = $this->parts;
    
    //Sort the parts by priority to execute faster checks first
    usort($parts, function ($p1, $p2) {
        $pr1 = $p1->getPriority();
        $pr2 = $p2->getPriority();
        if ($pr1 === $pr2) {
            return 0;
        }
        elseif ($pr1 < $pr2) {
            return -1;
        }
        else {
            return 1;
        }
    });
    $filter = function ($node, $parent) use ($parts) {
        foreach ($parts as $part) {
            if (!$part->check($node, $parent)) {
                return false;
            }
        }
        return true;
    };
    switch ($this->operator) {
        case " ":
        case ">":
            $children = $this->operator === ">";
            $matches->map(function ($curNode) use ($filter, $children) {
                $ret = array();
                $curNode->traverse(function ($node, $parent) use ($filter, $children, &$ret) {
                    if ($filter($node, $parent)) {
                        $ret[] = array(
                            $node,
                            $parent,
                        );
                    }
                    if ($children) {
                        return Traverser::DONT_TRAVERSE_CHILD_NODES;
                    }
                }, array(
                    "skipStartingNode" => true,
                    "passParentNode" => true,
                ));
                return $ret;
            });
            break;
        case "~":
        case "+":
            $adjacent = $this->operator === "+";
            $matches->map(function ($node, $parent) use ($filter, $adjacent) {
                $ret = array();
                $evaluate = false;
                $props = $parent ? Utils::getExpandedNodeProperties($parent) : array();
                foreach ($props as $propNode) {
                    if ($evaluate) {
                        if ($propNode && $filter($propNode, $parent)) {
                            $ret[] = array(
                                $propNode,
                                $parent,
                            );
                        }
                        if ($adjacent) {
                            break;
                        }
                    }
                    elseif ($propNode === $node) {
                        $evaluate = true;
                    }
                }
                return $ret;
            });
            break;
        default:
            $matches->filter($filter);
            break;
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal