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\LoaderCode
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;
}