summaryrefslogtreecommitdiff
path: root/src/Nodes/NodeTrait.php
diff options
context:
space:
mode:
authorAndres Rey <[email protected]>2019-06-17 20:29:32 +0100
committerAndres Rey <[email protected]>2019-06-17 20:29:32 +0100
commitdf9d3e1634bc76978baa989a6cee4035a2a346d4 (patch)
tree01a43b02943eeb95a06640bd20a18943cdd598e0 /src/Nodes/NodeTrait.php
parente38cbfaebd1f826233f7a0e07c66a52f44e9b796 (diff)
Remove getChildren function, implement a fake DOMNodeList class. Prepare everything to support newer versions of libxml2
Diffstat (limited to 'src/Nodes/NodeTrait.php')
-rw-r--r--src/Nodes/NodeTrait.php26
1 files changed, 3 insertions, 23 deletions
diff --git a/src/Nodes/NodeTrait.php b/src/Nodes/NodeTrait.php
index 9ef1fa2..2ce4383 100644
--- a/src/Nodes/NodeTrait.php
+++ b/src/Nodes/NodeTrait.php
@@ -313,26 +313,6 @@ trait NodeTrait
}
/**
- * Returns the children of the current node.
- *
- * @param bool $filterEmptyDOMText Filter empty DOMText nodes?
- *
- * @return array
- */
- public function getChildren($filterEmptyDOMText = false)
- {
- $ret = iterator_to_array($this->childNodes);
- if ($filterEmptyDOMText) {
- // Array values is used to discard the key order. Needs to be 0 to whatever without skipping any number
- $ret = array_values(array_filter($ret, function ($node) {
- return $node->nodeName !== '#text' || mb_strlen(trim($node->nodeValue));
- }));
- }
-
- return $ret;
- }
-
- /**
* Return an array indicating how many rows and columns this table has.
*
* @return array
@@ -418,12 +398,12 @@ trait NodeTrait
public function hasSingleTagInsideElement($tag)
{
// There should be exactly 1 element child with given tag
- if (count($children = $this->getChildren(true)) !== 1 || $children[0]->nodeName !== $tag) {
+ if (count($children = NodeUtility::filterTextNodes($this->childNodes)) !== 1 || $children[0]->nodeName !== $tag) {
return false;
}
// And there should be no text nodes with real content
- return array_reduce($children, function ($carry, $child) {
+ return array_reduce(iterator_to_array($children), function ($carry, $child) {
if (!$carry === false) {
return false;
}
@@ -443,7 +423,7 @@ trait NodeTrait
{
$result = false;
if ($this->hasChildNodes()) {
- foreach ($this->getChildren() as $child) {
+ foreach ($this->childNodes as $child) {
if (in_array($child->nodeName, $this->divToPElements)) {
$result = true;
} else {