1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46:
<?php
namespace SDom\SelectorMatcher;
use SDom\Node\Element;
use Symfony\Component\CssSelector\Node\ElementNode;
use Symfony\Component\CssSelector\Node\NodeInterface;
/**
* @pattern *
* @meaning any element
* @link https://www.w3.org/TR/css3-selectors/#universal-selector
*
* @pattern E
* @meaning an element of type E
* @link https://www.w3.org/TR/css3-selectors/#type-selectors
*
* Trait ElementNodeTrait
* @package SDom\SelectorMatcher
*/
trait ElementNodeTrait
{
/**
* @param ElementNode $token
* @param Element $node
* @return bool
*/
protected function matchElementNode(ElementNode $token, Element $node): bool
{
// target element tag name may be null, directly return true as ElementNode tokens have no sub-selectors
if (null === $token->getElement()) {
return true;
}
// node tag name must match
return $node->getTag() === $token->getElement();
}
/**
* @param NodeInterface $token
* @param Element $node
* @param Element|null $effectiveRoot
* @return bool
*/
abstract public function match(NodeInterface $token, Element $node, Element $effectiveRoot = null): bool;
}