@@ -634,21 +634,50 @@ public function validateSchema(\DOMDocument $dom)
634
634
EOF
635
635
;
636
636
637
- if (\ LIBXML_VERSION < 20900 ) {
637
+ if ($ this -> shouldEnableEntityLoader () ) {
638
638
$ disableEntities = libxml_disable_entity_loader (false );
639
639
$ valid = @$ dom ->schemaValidateSource ($ source );
640
640
libxml_disable_entity_loader ($ disableEntities );
641
641
} else {
642
642
$ valid = @$ dom ->schemaValidateSource ($ source );
643
643
}
644
-
645
644
foreach ($ tmpfiles as $ tmpfile ) {
646
645
@unlink ($ tmpfile );
647
646
}
648
647
649
648
return $ valid ;
650
649
}
651
650
651
+ private function shouldEnableEntityLoader (): bool
652
+ {
653
+ // Version prior to 8.0 can be enabled without deprecation
654
+ if (\PHP_VERSION_ID < 80000 ) {
655
+ return true ;
656
+ }
657
+
658
+ static $ dom , $ schema ;
659
+ if (null === $ dom ) {
660
+ $ dom = new \DOMDocument ();
661
+ $ dom ->loadXML ('<?xml version="1.0"?><test/> ' );
662
+
663
+ $ tmpfile = tempnam (sys_get_temp_dir (), 'symfony ' );
664
+ register_shutdown_function (static function () use ($ tmpfile ) {
665
+ @unlink ($ tmpfile );
666
+ });
667
+ $ schema = '<?xml version="1.0" encoding="utf-8"?>
668
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
669
+ <xsd:include schemaLocation="file:/// ' .str_replace ('\\' , '/ ' , $ tmpfile ).'" />
670
+ </xsd:schema> ' ;
671
+ file_put_contents ($ tmpfile , '<?xml version="1.0" encoding="utf-8"?>
672
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
673
+ <xsd:element name="test" type="testType" />
674
+ <xsd:complexType name="testType"/>
675
+ </xsd:schema> ' );
676
+ }
677
+
678
+ return !@$ dom ->schemaValidateSource ($ schema );
679
+ }
680
+
652
681
private function validateAlias (\DOMElement $ alias , string $ file )
653
682
{
654
683
foreach ($ alias ->attributes as $ name => $ node ) {
0 commit comments