Skip to content

Commit 2713a61

Browse files
committed
Fix error handling
1 parent c9536f4 commit 2713a61

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/SchemaValidatableElementTrait.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
use function defined;
1414
use function file_exists;
1515
use function implode;
16+
use function libxml_clear_errors;
1617
use function libxml_get_errors;
18+
use function libxml_use_internal_errors;
1719
use function sprintf;
1820
use function trim;
1921

@@ -32,6 +34,9 @@ trait SchemaValidatableElementTrait
3234
*/
3335
public static function schemaValidate(DOMDocument $document): DOMDocument
3436
{
37+
$internalErrors = libxml_use_internal_errors(true);
38+
libxml_clear_errors();
39+
3540
$schemaFile = self::getSchemaFile();
3641
// Must suppress the warnings here in order to throw them as an error below.
3742
$result = @$document->schemaValidate($schemaFile);
@@ -48,6 +53,9 @@ public static function schemaValidate(DOMDocument $document): DOMDocument
4853
));
4954
}
5055

56+
libxml_use_internal_errors($internalErrors);
57+
libxml_clear_errors();
58+
5159
return $document;
5260
}
5361

0 commit comments

Comments
 (0)