updated-packages

This commit is contained in:
RafficMohammed
2023-01-08 00:13:22 +05:30
parent 3ff7df7487
commit da241bacb6
12659 changed files with 563377 additions and 510538 deletions

View File

@@ -41,7 +41,7 @@ class XliffUtils
$namespace = $xliff->attributes->getNamedItem('xmlns');
if ($namespace) {
if (0 !== substr_compare('urn:oasis:names:tc:xliff:document:', $namespace->nodeValue, 0, 34)) {
throw new InvalidArgumentException(sprintf('Not a valid XLIFF namespace "%s"', $namespace));
throw new InvalidArgumentException(sprintf('Not a valid XLIFF namespace "%s".', $namespace));
}
return substr($namespace, 34);
@@ -61,23 +61,56 @@ class XliffUtils
{
$xliffVersion = static::getVersionNumber($dom);
$internalErrors = libxml_use_internal_errors(true);
$disableEntities = libxml_disable_entity_loader(false);
$isValid = @$dom->schemaValidateSource(self::getSchema($xliffVersion));
if (!$isValid) {
libxml_disable_entity_loader($disableEntities);
return self::getXmlErrors($internalErrors);
if ($shouldEnable = self::shouldEnableEntityLoader()) {
$disableEntities = libxml_disable_entity_loader(false);
}
try {
$isValid = @$dom->schemaValidateSource(self::getSchema($xliffVersion));
if (!$isValid) {
return self::getXmlErrors($internalErrors);
}
} finally {
if ($shouldEnable) {
libxml_disable_entity_loader($disableEntities);
}
}
libxml_disable_entity_loader($disableEntities);
$dom->normalizeDocument();
libxml_clear_errors();
libxml_use_internal_errors($internalErrors);
return array();
return [];
}
private static function shouldEnableEntityLoader(): bool
{
// Version prior to 8.0 can be enabled without deprecation
if (\PHP_VERSION_ID < 80000) {
return true;
}
static $dom, $schema;
if (null === $dom) {
$dom = new \DOMDocument();
$dom->loadXML('<?xml version="1.0"?><test/>');
$tmpfile = tempnam(sys_get_temp_dir(), 'symfony');
register_shutdown_function(static function () use ($tmpfile) {
@unlink($tmpfile);
});
$schema = '<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:include schemaLocation="file:///'.str_replace('\\', '/', $tmpfile).'" />
</xsd:schema>';
file_put_contents($tmpfile, '<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="test" type="testType" />
<xsd:complexType name="testType"/>
</xsd:schema>');
}
return !@$dom->schemaValidateSource($schema);
}
public static function getErrorsAsString(array $xmlErrors): string
@@ -86,7 +119,7 @@ class XliffUtils
foreach ($xmlErrors as $error) {
$errorsAsString .= sprintf("[%s %s] %s (in %s - line %d, column %d)\n",
LIBXML_ERR_WARNING === $error['level'] ? 'WARNING' : 'ERROR',
\LIBXML_ERR_WARNING === $error['level'] ? 'WARNING' : 'ERROR',
$error['code'],
$error['message'],
$error['file'],
@@ -143,16 +176,16 @@ class XliffUtils
*/
private static function getXmlErrors(bool $internalErrors): array
{
$errors = array();
$errors = [];
foreach (libxml_get_errors() as $error) {
$errors[] = array(
'level' => LIBXML_ERR_WARNING == $error->level ? 'WARNING' : 'ERROR',
$errors[] = [
'level' => \LIBXML_ERR_WARNING == $error->level ? 'WARNING' : 'ERROR',
'code' => $error->code,
'message' => trim($error->message),
'file' => $error->file ?: 'n/a',
'line' => $error->line,
'column' => $error->column,
);
];
}
libxml_clear_errors();