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

Breadcrumb

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

function XmlFileLoader::parseRoute

Parses a route and adds it to the RouteCollection.

Throws

\InvalidArgumentException When the XML is invalid

1 call to XmlFileLoader::parseRoute()
XmlFileLoader::parseNode in vendor/symfony/routing/Loader/XmlFileLoader.php
Parses a node from a loaded XML file.

File

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

Class

XmlFileLoader
XmlFileLoader loads XML routing files.

Namespace

Symfony\Component\Routing\Loader

Code

protected function parseRoute(RouteCollection $collection, \DOMElement $node, string $path) : void {
    if ('' === ($id = $node->getAttribute('id'))) {
        throw new \InvalidArgumentException(\sprintf('The <route> element in file "%s" must have an "id" attribute.', $path));
    }
    if ('' !== ($alias = $node->getAttribute('alias'))) {
        $alias = $collection->addAlias($id, $alias);
        if ($deprecationInfo = $this->parseDeprecation($node, $path)) {
            $alias->setDeprecated($deprecationInfo['package'], $deprecationInfo['version'], $deprecationInfo['message']);
        }
        return;
    }
    $schemes = preg_split('/[\\s,\\|]++/', $node->getAttribute('schemes'), -1, \PREG_SPLIT_NO_EMPTY);
    $methods = preg_split('/[\\s,\\|]++/', $node->getAttribute('methods'), -1, \PREG_SPLIT_NO_EMPTY);
    [
        $defaults,
        $requirements,
        $options,
        $condition,
        $paths,
        ,
        $hosts,
    ] = $this->parseConfigs($node, $path);
    if (!$paths && '' === $node->getAttribute('path')) {
        throw new \InvalidArgumentException(\sprintf('The <route> element in file "%s" must have a "path" attribute or <path> child nodes.', $path));
    }
    if ($paths && '' !== $node->getAttribute('path')) {
        throw new \InvalidArgumentException(\sprintf('The <route> element in file "%s" must not have both a "path" attribute and <path> child nodes.', $path));
    }
    $routes = $this->createLocalizedRoute($collection, $id, $paths ?: $node->getAttribute('path'));
    $routes->addDefaults($defaults);
    $routes->addRequirements($requirements);
    $routes->addOptions($options);
    $routes->setSchemes($schemes);
    $routes->setMethods($methods);
    $routes->setCondition($condition);
    if (null !== $hosts) {
        $this->addHost($routes, $hosts);
    }
}

API Navigation

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