public function DumperPrefixCollection::addPrefixRoute

Adds a route in the tree.

Parameters

DumperRoute $route The route:

Return value

DumperPrefixCollection The node the route was added to

Throws

\LogicException

File

drupal/core/vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/DumperPrefixCollection.php, line 55

Class

DumperPrefixCollection
Prefix tree of routes preserving routes order.

Namespace

Symfony\Component\Routing\Matcher\Dumper

Code

public function addPrefixRoute(DumperRoute $route) {
  $prefix = $route
    ->getRoute()
    ->compile()
    ->getStaticPrefix();

  // Same prefix, add to current leave
  if ($this->prefix === $prefix) {
    $this
      ->add($route);
    return $this;
  }

  // Prefix starts with route's prefix
  if ('' === $this->prefix || 0 === strpos($prefix, $this->prefix)) {
    $collection = new DumperPrefixCollection();
    $collection
      ->setPrefix(substr($prefix, 0, strlen($this->prefix) + 1));
    $this
      ->add($collection);
    return $collection
      ->addPrefixRoute($route);
  }

  // No match, fallback to parent (recursively)
  if (null === ($parent = $this
    ->getParent())) {
    throw new \LogicException("The collection root must not have a prefix");
  }
  return $parent
    ->addPrefixRoute($route);
}