private function XliffFileLoader::parseFile in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/symfony/translation/Loader/XliffFileLoader.php \Symfony\Component\Translation\Loader\XliffFileLoader::parseFile()
Validates and parses the given file into a SimpleXMLElement.
Parameters
string $file:
Return value
\SimpleXMLElement
Throws
\RuntimeException
1 call to XliffFileLoader::parseFile()
- XliffFileLoader::load in vendor/
symfony/ translation/ Loader/ XliffFileLoader.php - Loads a locale.
File
- vendor/
symfony/ translation/ Loader/ XliffFileLoader.php, line 121
Class
- XliffFileLoader
- XliffFileLoader loads translations from XLIFF files.
Namespace
Symfony\Component\Translation\LoaderCode
private function parseFile($file) {
try {
$dom = XmlUtils::loadFile($file);
} catch (\InvalidArgumentException $e) {
throw new InvalidResourceException(sprintf('Unable to load "%s": %s', $file, $e
->getMessage()), $e
->getCode(), $e);
}
$internalErrors = libxml_use_internal_errors(true);
$location = str_replace('\\', '/', __DIR__) . '/schema/dic/xliff-core/xml.xsd';
$parts = explode('/', $location);
if (0 === stripos($location, 'phar://')) {
$tmpfile = tempnam(sys_get_temp_dir(), 'sf2');
if ($tmpfile) {
copy($location, $tmpfile);
$parts = explode('/', str_replace('\\', '/', $tmpfile));
}
}
$drive = '\\' === DIRECTORY_SEPARATOR ? array_shift($parts) . '/' : '';
$location = 'file:///' . $drive . implode('/', array_map('rawurlencode', $parts));
$source = file_get_contents(__DIR__ . '/schema/dic/xliff-core/xliff-core-1.2-strict.xsd');
$source = str_replace('http://www.w3.org/2001/xml.xsd', $location, $source);
if (!@$dom
->schemaValidateSource($source)) {
throw new InvalidResourceException(sprintf('Invalid resource provided: "%s"; Errors: %s', $file, implode("\n", $this
->getXmlErrors($internalErrors))));
}
$dom
->normalizeDocument();
libxml_clear_errors();
libxml_use_internal_errors($internalErrors);
return array(
simplexml_import_dom($dom),
strtoupper($dom->encoding),
);
}