Skip to content

Commit

Permalink
Small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Imangazaliev committed Mar 15, 2016
1 parent 4e1134a commit c18683b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/DiDom/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,14 @@ public function appendChild($nodes)
throw new InvalidArgumentException(sprintf('Argument 1 passed to %s must be an instance of %s\Element or DOMElement, %s given', __METHOD__, __NAMESPACE__, (is_object($node) ? get_class($node) : gettype($node))));
}

$this->displayErrors(false);

$cloned = $node->cloneNode(true);
$newNode = $this->document->importNode($cloned, true);

$this->document->appendChild($newNode);

$this->displayErrors(true);
}

return $this;
Expand Down Expand Up @@ -128,19 +132,28 @@ public function load($string, $isFile = false, $type = 'html', $options = 0)

$this->type = strtolower($type);

libxml_use_internal_errors(true);
libxml_disable_entity_loader(true);
$this->displayErrors(false);

$this->type === 'xml' ? $this->document->loadXml($string, $options) : $this->document->loadHtml($string, $options);

libxml_clear_errors();

libxml_disable_entity_loader(false);
libxml_use_internal_errors(false);
$this->displayErrors(true);

return $this;
}

protected function displayErrors($display = true)
{
if ($display) {
libxml_clear_errors();

libxml_disable_entity_loader(false);
libxml_use_internal_errors(false);
} else {
libxml_use_internal_errors(true);
libxml_disable_entity_loader(true);
}
}

/**
* Load HTML from a string.
*
Expand Down
8 changes: 8 additions & 0 deletions src/DiDom/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,18 @@ public function appendChild($nodes)
throw new InvalidArgumentException(sprintf('Argument 1 passed to %s must be an instance of %s\Element or DOMElement, %s given', __METHOD__, __NAMESPACE__, (is_object($node) ? get_class($node) : gettype($node))));
}

libxml_use_internal_errors(true);
libxml_disable_entity_loader(true);

$cloned = $node->cloneNode(true);
$newNode = $this->node->ownerDocument->importNode($cloned, true);

$this->node->appendChild($newNode);

libxml_clear_errors();

libxml_disable_entity_loader(false);
libxml_use_internal_errors(false);
}

return $this;
Expand Down

0 comments on commit c18683b

Please sign in to comment.