Modern DOM library written in PHP for HTML documents
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
704 B

<?php
declare(strict_types=1);
namespace dW\HTML5;
trait Compare {
protected function compare($needle, Element $context): \DOMNode {
if (is_string($needle)) {
if ($context->nodeName == $needle) {
return $this;
}
} elseif ($needle instanceof \DOMNode) {
if ($context->isSameNode($needle)) {
return $context;
}
} elseif ($needle instanceof \Closure) {
if ($needle($context) === true) {
return $context;
}
} else {
throw new DOMException(DOMException::STRING_OR_CLOSURE_EXPECTED, gettype($needle));
}
return null;
}
}