From 2713a61cc2703ed859327513620f03155e66ee1f Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Tue, 17 Dec 2024 00:09:14 +0100 Subject: [PATCH] Fix error handling --- src/SchemaValidatableElementTrait.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/SchemaValidatableElementTrait.php b/src/SchemaValidatableElementTrait.php index 0c79c0e..9a44b66 100644 --- a/src/SchemaValidatableElementTrait.php +++ b/src/SchemaValidatableElementTrait.php @@ -13,7 +13,9 @@ use function defined; use function file_exists; use function implode; +use function libxml_clear_errors; use function libxml_get_errors; +use function libxml_use_internal_errors; use function sprintf; use function trim; @@ -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); @@ -48,6 +53,9 @@ public static function schemaValidate(DOMDocument $document): DOMDocument )); } + libxml_use_internal_errors($internalErrors); + libxml_clear_errors(); + return $document; }