protected function XmlFileLoader::loadFile

Loads an XML file.

Parameters

string $file An XML file path:

Return value

\DOMDocument

Throws

\InvalidArgumentException When loading of XML file returns error

1 call to XmlFileLoader::loadFile()
XmlFileLoader::load in drupal/core/vendor/symfony/routing/Symfony/Component/Routing/Loader/XmlFileLoader.php
Loads an XML file.

File

drupal/core/vendor/symfony/routing/Symfony/Component/Routing/Loader/XmlFileLoader.php, line 171

Class

XmlFileLoader
XmlFileLoader loads XML routing files.

Namespace

Symfony\Component\Routing\Loader

Code

protected function loadFile($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);
  return $dom;
}