You are here

private function XliffFileLoader::parseFile in Plug 7

Validates and parses the given file into a SimpleXMLElement.

Parameters

string $file:

Return value

\SimpleXMLElement

Throws

\RuntimeException

InvalidResourceException

1 call to XliffFileLoader::parseFile()
XliffFileLoader::load in lib/Symfony/translation/Loader/XliffFileLoader.php
@api

File

lib/Symfony/translation/Loader/XliffFileLoader.php, line 125

Class

XliffFileLoader
XliffFileLoader loads translations from XLIFF files.

Namespace

Symfony\Component\Translation\Loader

Code

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),
  );
}