function Attribute::check
Returns true if the selector part matches the given node, false otherwise
Parameters
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\PartCode
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;
}
}