Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. XmlFileLoader.php

function XmlFileLoader::parseFileToDOM

Parses an XML file to a \DOMDocument.

Throws

InvalidArgumentException When loading of XML file returns error

1 call to XmlFileLoader::parseFileToDOM()
XmlFileLoader::load in vendor/symfony/dependency-injection/Loader/XmlFileLoader.php

File

vendor/symfony/dependency-injection/Loader/XmlFileLoader.php, line 456

Class

XmlFileLoader
XmlFileLoader loads XML files service definitions.

Namespace

Symfony\Component\DependencyInjection\Loader

Code

private function parseFileToDOM(string $file) : \DOMDocument {
    try {
        $dom = XmlUtils::loadFile($file, $this->validateSchema(...));
    } catch (\InvalidArgumentException $e) {
        $invalidSecurityElements = [];
        $errors = explode("\n", $e->getMessage());
        foreach ($errors as $i => $error) {
            if (preg_match("#^\\[ERROR 1871] Element '\\{http://symfony\\.com/schema/dic/security}([^']+)'#", $error, $matches)) {
                $invalidSecurityElements[$i] = $matches[1];
            }
        }
        if ($invalidSecurityElements) {
            $dom = XmlUtils::loadFile($file);
            foreach ($invalidSecurityElements as $errorIndex => $tagName) {
                foreach ($dom->getElementsByTagNameNS('http://symfony.com/schema/dic/security', $tagName) as $element) {
                    if (!($parent = $element->parentNode)) {
                        continue;
                    }
                    if ('http://symfony.com/schema/dic/security' !== $parent->namespaceURI) {
                        continue;
                    }
                    if ('provider' === $parent->localName || 'firewall' === $parent->localName) {
                        unset($errors[$errorIndex]);
                    }
                }
            }
        }
        if ($errors) {
            throw new InvalidArgumentException(\sprintf('Unable to parse file "%s": ', $file) . implode("\n", $errors), $e->getCode(), $e);
        }
    }
    $this->validateExtensions($dom, $file);
    return $dom;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal