summaryrefslogtreecommitdiff
path: root/src/Nodes/NodeTrait.php
diff options
context:
space:
mode:
authorAndres Rey <[email protected]>2018-11-07 19:11:50 +0000
committerAndres Rey <[email protected]>2018-11-07 19:11:50 +0000
commit1d86d0898c8d0d1c90735db541d3a0f17868737f (patch)
tree5483c164247d8cf0f34ab23fb9e26cbc0e707398 /src/Nodes/NodeTrait.php
parent0292ff115cfd28d472b378329a9932436e251fc7 (diff)
Add third parameter of "hasAncestorTag" as a callable optional function
Diffstat (limited to 'src/Nodes/NodeTrait.php')
-rw-r--r--src/Nodes/NodeTrait.php8
1 files changed, 5 insertions, 3 deletions
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++;
}