Skip to content

Commit 0411f10

Browse files
committed
bug #37763 Fix deprecated libxml_disable_entity_loader (jderusse)
This PR was merged into the 3.4 branch. Discussion ---------- Fix deprecated libxml_disable_entity_loader | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | / | License | MIT | Doc PR | / Fix deprecation `Function libxml_disable_entity_loader() is deprecated` triggered by php/php-src#5867 in PHP8 Commits ------- 1f19da3936 Fix deprecated libxml_disable_entity_loader
2 parents 009fb11 + 7c9e443 commit 0411f10

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

Loader/XliffFileLoader.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,18 @@ private function validateSchema($file, \DOMDocument $dom, $schema)
189189
{
190190
$internalErrors = libxml_use_internal_errors(true);
191191

192-
$disableEntities = libxml_disable_entity_loader(false);
193-
194-
if (!@$dom->schemaValidateSource($schema)) {
192+
if (LIBXML_VERSION < 20900) {
193+
$disableEntities = libxml_disable_entity_loader(false);
194+
$isValid = @$dom->schemaValidateSource($schema);
195195
libxml_disable_entity_loader($disableEntities);
196+
} else {
197+
$isValid = @$dom->schemaValidateSource($schema);
198+
}
196199

200+
if (!$isValid) {
197201
throw new InvalidResourceException(sprintf('Invalid resource provided: "%s"; Errors: ', $file).implode("\n", $this->getXmlErrors($internalErrors)));
198202
}
199203

200-
libxml_disable_entity_loader($disableEntities);
201-
202204
$dom->normalizeDocument();
203205

204206
libxml_clear_errors();

Tests/Loader/XliffFileLoaderTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,17 @@ public function testLoadWithInternalErrorsEnabled()
4949

5050
public function testLoadWithExternalEntitiesDisabled()
5151
{
52-
$disableEntities = libxml_disable_entity_loader(true);
52+
if (LIBXML_VERSION < 20900) {
53+
$disableEntities = libxml_disable_entity_loader(true);
54+
}
5355

5456
$loader = new XliffFileLoader();
5557
$resource = __DIR__.'/../fixtures/resources.xlf';
5658
$catalogue = $loader->load($resource, 'en', 'domain1');
5759

58-
libxml_disable_entity_loader($disableEntities);
60+
if (LIBXML_VERSION < 20900) {
61+
libxml_disable_entity_loader($disableEntities);
62+
}
5963

6064
$this->assertEquals('en', $catalogue->getLocale());
6165
$this->assertEquals([new FileResource($resource)], $catalogue->getResources());

0 commit comments

Comments
 (0)