private function XmlFileLoader::parseFile

Parses a XML file.

Parameters

string $file Path to a file:

Throws

InvalidArgumentException When loading of XML file returns error

1 call to XmlFileLoader::parseFile()
XmlFileLoader::load in drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php
Loads an XML file.

File

drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php, line 205

Class

XmlFileLoader
XmlFileLoader loads XML files service definitions.

Namespace

Symfony\Component\DependencyInjection\Loader

Code

private function parseFile($file) {
  $internalErrors = libxml_use_internal_errors(true);
  $disableEntities = libxml_disable_entity_loader(true);
  libxml_clear_errors();
  $dom = new \DOMDocument();
  $dom->validateOnParse = true;
  if (!$dom
    ->loadXML(file_get_contents($file), LIBXML_NONET | (defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0))) {
    libxml_disable_entity_loader($disableEntities);
    throw new \InvalidArgumentException(implode("\n", $this
      ->getXmlErrors($internalErrors)));
  }
  $dom
    ->normalizeDocument();
  libxml_use_internal_errors($internalErrors);
  libxml_disable_entity_loader($disableEntities);
  foreach ($dom->childNodes as $child) {
    if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
      throw new \InvalidArgumentException('Document types are not allowed.');
    }
  }
  $this
    ->validate($dom, $file);
  return simplexml_import_dom($dom, 'Symfony\\Component\\DependencyInjection\\SimpleXMLElement');
}