From 1d86d0898c8d0d1c90735db541d3a0f17868737f Mon Sep 17 00:00:00 2001 From: Andres Rey Date: Wed, 7 Nov 2018 19:11:50 +0000 Subject: Add third parameter of "hasAncestorTag" as a callable optional function --- src/Nodes/NodeTrait.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/Nodes/NodeTrait.php') diff --git a/src/Nodes/NodeTrait.php b/src/Nodes/NodeTrait.php index c08b59f..f641b2d 100644 --- a/src/Nodes/NodeTrait.php +++ b/src/Nodes/NodeTrait.php @@ -365,13 +365,13 @@ trait NodeTrait * Check if a given node has one of its ancestor tag name matching the * provided one. * - * @param DOMElement $node * @param string $tagName * @param int $maxDepth + * @param callable $filterFn * * @return bool */ - public function hasAncestorTag($tagName, $maxDepth = 3) + public function hasAncestorTag($tagName, $maxDepth = 3, callable $filterFn = null) { $depth = 0; $node = $this; @@ -380,9 +380,11 @@ trait NodeTrait if ($maxDepth > 0 && $depth > $maxDepth) { return false; } - if ($node->parentNode->nodeName === $tagName) { + + if ($node->parentNode->nodeName === $tagName && (!$filterFn || $filterFn($node->parentNode))) { return true; } + $node = $node->parentNode; $depth++; } -- cgit v1.2.3