Skip to content

Commit

Permalink
Fix error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Dec 16, 2024
1 parent c9536f4 commit 082a473
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/SchemaValidatableElementTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use function defined;
use function file_exists;
use function implode;
use function libxml_clear_errors;
use function libxml_use_internal_errors;
use function libxml_get_errors;
use function sprintf;
use function trim;
Expand All @@ -32,6 +34,9 @@ trait SchemaValidatableElementTrait
*/
public static function schemaValidate(DOMDocument $document): DOMDocument
{
$internalErrors = libxml_use_internal_errors(true);
libxml_clear_errors();

$schemaFile = self::getSchemaFile();
// Must suppress the warnings here in order to throw them as an error below.
$result = @$document->schemaValidate($schemaFile);
Expand All @@ -48,6 +53,9 @@ public static function schemaValidate(DOMDocument $document): DOMDocument
));
}

libxml_use_internal_errors($internalErrors);
libxml_clear_errors();

return $document;
}

Expand Down

0 comments on commit 082a473

Please sign in to comment.