Adds route path to the given node. Merges with existing one,
if possible, otherwise creates new tree node.

@param TreeNode $node
@param RoutePath $path
@param Route $route
@param int $index
@return TreeNode
973127
private function addPathPartToTree(TreeNode $node, RoutePath $path, Route $route, int $index): TreeNode
    {
        $pathNode = $this->pathToNode($path, $route, $index);

        foreach ($node->getChildren() as $child) {
            if ($child->withoutChildren() == $pathNode->withoutChildren()) {
                return $child;
            }
        }

        $node->addChild($pathNode);

        return $pathNode;
    }
1120737
private function getRelativePath(ResourceNode $root, ResourceNode $node, $path = '')
    {
        if ($node->getParent() !== $root->getParent() && null !== $node->getParent()) {
            $path = $node->getParent()->getName().DIRECTORY_SEPARATOR.$path;
            $path = $this->getRelativePath($root, $node->getParent(), $path);
        }

        return $path;
    }
1342711
public function add(Route $route): self
    {
        if ($route->uri === ""
            || $route->method === 0b0
            || $route->action === null) {
            $this->logger->error("Route incomplete. Unable to add");
            $this->logger->debug("Incomplete Route", [$route]);
            throw new Exception\RouteIncompleteException(
                "Retrieved Route is not complete and can not be stored"
            );
        }

        // store default route
        if ($route->isDefault) {
            if ($this->defaultRoute === null) {
                $this->defaultRoute = $route;
            } else {
                $this->logger->debug(
                    "Default route already added to container, skipping add.",
                    ["route" => $route, "storedDefault" => $this->defaultRoute]
                );
            }
        }

        // store 404 route
        if ($route->is404) {
            if ($this->e404Route === null) {
                $this->e404Route = $route;
                $this->logger->info("404 route added to Route Container");
            } else {
                $this->logger->debug(
                    "404 route already added to container, skipping add.",
                    ["route" => $route, "stored404" => $this->e404Route]
                );
            }

            return $this;
        }

        // store route to regular container
        $this->routes[] = $route;

        $this->logger->info(
            "Route successfully added to Container",
            ["uri" => $route->uri]
        );

        return $this;
    }
536722
public static function addRoute($path, $target, $method = 'GET')
    {
        $router = Router::getInstance();
        $router->altoRouter->map($method, $path, $target);
    }
533784
public function add(string $path, $callable): Route{
		$route = new Route($path, $callable);
		$this->routes[] = $route;
		return $route;
	}
1309298
public static function add($route){
      if (is_a($route, 'Route')){

        // Add to tag map
        if ($route->tag) static::$tags[$route->tag] =& $route;

        // Optimize tree
        if (Options::get('core.route.auto_optimize', true)){
          $base =& static::$optimized_tree;
          foreach (explode('/',trim(preg_replace('#^(.+?)\(?:.+$#','$1',$route->URLPattern),'/')) as $segment) {
            $segment = trim($segment,'(');
            if (!isset($base[$segment])) $base[$segment] = [];
            $base =& $base[$segment];
          }
          $base[] =& $route;
        }
      }

      // Add route to active group
      if ( isset(static::$group[0]) ) static::$group[0]->add($route);

      return static::$routes[implode('', static::$prefix)][] = $route;
    }
1066178
public function add(Route $route): self{
        if(isset($this->leaves[$route])){
            throw new \InvalidArgumentException(
                "Route is already registered."
            );
        }

        if(array_key_exists($route->getName(), $this->routes)){
            throw new \InvalidArgumentException(
                "Same name ({$route->getName()}) route is already registered."
            );
        }

        $queue  = new \SplQueue();

        foreach(explode("/", $route->getPath()) as $segment){
            $queue->enqueue($segment);
        }

        $queue->dequeue(); // 先頭のセグメントはすでにある(ルートノード)

        $node   = $this->rootNode;

        while(!$queue->isEmpty()){
            $segment    = $queue->dequeue();

            $node->addChild($segment);

            $node   = $node->getChild($segment);
        }

        $node->addRoute($route);

        $this->routes[$route->getName()]    = $route;
        $this->leaves[$route]               = $node;

        return $this;
    }
444604
public function route(RouterInterface $router, string $path, string $filter, array &$vars) : bool
    {
        // dispatch if no paths remain in buffer(means last node)
        if (empty($path)){
            if (empty($filter)){
                $event = $this->filters['*'] ?? '';
            }
            else{
                $event = $this->filters[$filter] ?? $this->filters['*'] ?? '';
                if(!$event){
                    foreach($this->filters as $filter => $e){
                        if ($filter === self::FILTER_KEY_DEFAULT){
                            $event = $e;
                        }
                    }
                }
            }
            if (!empty($event)){
                $router->dispatch($vars, $event);
                return true;
            }
        }
        return parent::route($router, $path, $filter, $vars);
    }
1234339
public function addRoute(string $method, string $route, ...$callback)
    {
        $method = strtolower($method);
        $route = ltrim($route, '/');
        $group = rtrim($this->group, '/') . '/';
        $route = $group . $route;
        $scope = $this->middleware->count();
        $this->layer[$method][] = new Route(
            $method,
            $route,
            $callback,
            $scope,
            $this->group
        );

        return true;
    }
1219129
public function create(RouteCollection $routes): Tree
    {
        $routesArray = $routes->all();

        $routesPaths = array_map(function (Route $route) {
            return $this->serializer->serialize($route->getPath());
        }, $routesArray);

        $tree = new Tree();

        /** @var RoutePath[] $pathArray */
        foreach ($routesPaths as $index => $pathArray) {
            $route = $routesArray[$index];

            /** @var TreeNode $treeNode */
            $treeNode = $tree;

            foreach ($pathArray as $path) {
                $treeNode = $this->addPathPartToTree($treeNode, $path, $route, $index);
            }
        }

        return $tree;
    }
559117
public function addPath($route, array $pattern, $arity, $priority = 5)
    {
        $route = $this->validate($route);
        $key = $route->__toString() . '[' . $arity . ']';
        if (isset($this->paths[$key])) {
            if ($priority < $this->paths[$key]['priority']) {
                return;
            }
        }
        $this->paths[$key] = [
            'pattern' => $pattern,
            'priority' => $priority
        ];
    }
813434
public function createOptNode($path, $node)
    {
        return new OptNode(end($path), $this->exprcompiler->parse($node));
    }
457954
protected function generatePath(TreeNodeInterface $node, $parameters)
    {
        if ($this->requestContext->getParameter('_preview') || isset($parameters['_preview'])) {
            return $this->generatePreviewPath($node, $parameters);
        }

        $pathGenerator = new PathGenerator();
        $path = $pathGenerator->generatePath($node, $parameters);

        if ($path === '') {
            return $path;
        }

        $path = $this->generatePathPrefix($path, $node, $parameters);
        $path = $this->generatePathSuffix($path, $node, $parameters);
        $path = $this->generateQuery($path, $node, $parameters);

        return $path;
    }
62720
protected function addPathIfNeeded(EloquentNode $node)
    {
        // No path column
        if (!$this->pathKey) {
            return;
        }

        // Path was passed
        if ($node->getAttribute($this->pathKey)) {
            return;
        }

        $segment = $node->getAttribute($this->segmentKey);

        if ($node->isRoot() && $segment) {
            $node->setAttribute($this->pathKey, '/' . $this->cleanSegment($segment));
            return;
        }

        $parent = $this->guessParent($node);

        $parentPath = $parent->getPath();

        $node->setAttribute($this->pathKey, rtrim($parentPath, '/') . '/' . $this->cleanSegment($node->getPathSegment()));

    }
695529
public function add(Route $route)
    {
        $this->addRoute($route->methods(), $route->uri(), $route->handler(), $route->name());
    }
605441
public function addRoute(Route $route)
	{
		foreach ($route->getMethods() as $method)
		{
			$this->routes[$method][/*$route->uri*/] = $route;
		}
		
		$this->allRoutes[] = $route;

		return $this;
	}
264698
private function createRouteDefinition($routeName, Route $route)
    {
        if (null === $definition = $this->findRouteDefinitionByRouteName($routeName)) {
            $definition = new RouteDefinition($routeName, $this->resolveRouteOptions($route, $routeName));
            if (null === $parentRouteName = $definition->getParentRouteName()) {
                // If parent route name is null => home page child
                $definition->setParentRouteName($this->homeRouteName);
                $this->homeDefinition->appendChild($definition);
            } else {
                // Creates parent route definition if needed
                $parentRoute = $this->findRouteByName($parentRouteName);
                $parentDefinition = $this->createRouteDefinition($parentRouteName, $parentRoute);
                $parentDefinition->appendChild($definition);
            }
        }

        return $definition;
    }