Skip to content

Commit

Permalink
Fix warnings in loadFromXmlString, now throwing exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
HorstOeko committed Sep 15, 2024
1 parent 7676a7d commit e834cb4
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/XmlDocumentReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,19 @@ public function loadFromXmlString(string $source): XmlDocumentReader
*/
public function loadFromXmlFile(string $filename): XmlDocumentReader
{
$this->internalDomDocument->load($filename);
$prevUseInternalErrors = \libxml_use_internal_errors(true);

try {
$this->internalDomDocument->load($filename);
if (libxml_get_last_error()) {
throw new RuntimeException("Invalid XML detected.");
}
} catch (Throwable $e) {
throw new RuntimeException("Invalid XML detected.");
} finally {
libxml_clear_errors();
libxml_use_internal_errors($prevUseInternalErrors);
}

$this->registerDomXPath();
$this->registerNamespacesInDomXPath();
Expand Down

0 comments on commit e834cb4

Please sign in to comment.