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

Breadcrumb

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

function XmlFileLoader::parseDefaultNode

Recursively parses the value of a "default" element.

Throws

\InvalidArgumentException when the XML is invalid

1 call to XmlFileLoader::parseDefaultNode()
XmlFileLoader::parseDefaultsConfig in vendor/symfony/routing/Loader/XmlFileLoader.php
Parses the "default" elements.

File

vendor/symfony/routing/Loader/XmlFileLoader.php, line 365

Class

XmlFileLoader
XmlFileLoader loads XML routing files.

Namespace

Symfony\Component\Routing\Loader

Code

private function parseDefaultNode(\DOMElement $node, string $path) : array|bool|float|int|string|null {
    if ($this->isElementValueNull($node)) {
        return null;
    }
    switch ($node->localName) {
        case 'bool':
            return 'true' === trim($node->nodeValue) || '1' === trim($node->nodeValue);
        case 'int':
            return (int) trim($node->nodeValue);
        case 'float':
            return (double) trim($node->nodeValue);
        case 'string':
            return trim($node->nodeValue);
        case 'list':
            $list = [];
            foreach ($node->childNodes as $element) {
                if (!$element instanceof \DOMElement) {
                    continue;
                }
                if (self::NAMESPACE_URI !== $element->namespaceURI) {
                    continue;
                }
                $list[] = $this->parseDefaultNode($element, $path);
            }
            return $list;
        case 'map':
            $map = [];
            foreach ($node->childNodes as $element) {
                if (!$element instanceof \DOMElement) {
                    continue;
                }
                if (self::NAMESPACE_URI !== $element->namespaceURI) {
                    continue;
                }
                $map[$element->getAttribute('key')] = $this->parseDefaultNode($element, $path);
            }
            return $map;
        default:
            throw new \InvalidArgumentException(\sprintf('Unknown tag "%s" used in file "%s". Expected "bool", "int", "float", "string", "list", or "map".', $node->localName, $path));
    }
}

API Navigation

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