Adds a route in the tree.
DumperRoute $route The route:
DumperPrefixCollection The node the route was added to
\LogicException
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);
}