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

Breadcrumb

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

function Attribute::check

Returns true if the selector part matches the given node, false otherwise

Parameters

Node $node Node:

Node $parent Parent node:

Return value

bool

Overrides Part::check

File

vendor/mck89/peast/lib/Peast/Selector/Node/Part/Attribute.php, line 138

Class

Attribute
Selector part attribute class

Namespace

Peast\Selector\Node\Part

Code

public function check(Node $node, $parent = null) {
    $attr = $node;
    foreach ($this->names as $name) {
        $attrFound = false;
        if ($attr instanceof Node) {
            $props = Utils::getNodeProperties($attr);
            foreach ($props as $prop) {
                if ($prop["name"] === $name) {
                    $attrFound = true;
                    $attr = $attr->{$prop["getter"]}();
                    break;
                }
            }
        }
        if (!$attrFound) {
            return false;
        }
    }
    $bothStrings = is_string($attr) && is_string($this->value);
    switch ($this->operator) {
        case "=":
            if ($bothStrings) {
                if ($this->regex) {
                    return preg_match($this->value, $attr);
                }
                return $this->compareStr($this->value, $attr, $this->caseInsensitive, true, true);
            }
            if (is_int($attr) && is_float($this->value)) {
                return (double) $attr === $this->value;
            }
            return $attr === $this->value;
        case "<":
            if (is_float($this->value) && !is_float($attr) && !is_int($attr) && !is_string($attr)) {
                return false;
            }
            return $attr < $this->value;
        case ">":
            if (is_float($this->value) && !is_float($attr) && !is_int($attr) && !is_string($attr)) {
                return false;
            }
            return $attr > $this->value;
        case "<=":
            if (is_float($this->value) && !is_float($attr) && !is_int($attr) && !is_string($attr)) {
                return false;
            }
            return $attr <= $this->value;
        case ">=":
            if (is_float($this->value) && !is_float($attr) && !is_int($attr) && !is_string($attr)) {
                return false;
            }
            return $attr >= $this->value;
        case "^=":
        case "\$=":
        case "*=":
            return $this->compareStr($this->value, $attr, $this->caseInsensitive, $this->operator === "^=", $this->operator === "\$=");
        default:
            return true;
    }
}

API Navigation

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