private function addRouteToNode(
        RouteTreeNode $node,
        RouteContract $route,
        array $segments,
        int $segmentDepth,
        array $parameterIndexNameMap
    ): void {
        if (\count($segments) === 0) {
            $node->getContents()->addRoute($route, $parameterIndexNameMap);

            return;
        }

        $childSegmentMatcher = $this->getMatcher(\array_shift($segments), $parameterIndexNameMap);

        if ($node->getContents()->hasChildFor($childSegmentMatcher)) {
            $child = $node->getContents()->getChild($childSegmentMatcher);
        } else {
            $child = new RouteTreeNode(
                [$segmentDepth => $childSegmentMatcher],
                \count($segments) === 0 ? new MatchedRouteDataMap() : new ChildrenNodeCollection()
            );
            $node->getContents()->addChild($child);
        }

        $this->addRouteToNode($child, $route, $segments, $segmentDepth + 1, $parameterIndexNameMap);
    }
private function addRouteToNode(
        RouteTreeNode $node,
        RouteContract $route,
        array $segments,
        int $segmentDepth,
        array $parameterIndexNameMap
    ): void {
        if (\count($segments) === 0) {
            $node->getContents()->addRoute($route, $parameterIndexNameMap);

            return;
        }

        $childSegmentMatcher = $this->getMatcher(\array_shift($segments), $parameterIndexNameMap);

        if ($node->getContents()->hasChildFor($childSegmentMatcher)) {
            $child = $node->getContents()->getChild($childSegmentMatcher);
        } else {
            $child = new RouteTreeNode(
                [$segmentDepth => $childSegmentMatcher],
                \count($segments) === 0 ? new MatchedRouteDataMap() : new ChildrenNodeCollection()
            );
            $node->getContents()->addChild($child);
        }

        $this->addRouteToNode($child, $route, $segments, $segmentDepth + 1, $parameterIndexNameMap);
    }
private function addRouteToNode ( RouteTreeNode $ node , RouteContract $ route , array $ segments , int $ segmentDepth , array $ parameterIndexNameMap ) : void { if ( \ count ( $ segments ) === 0 ) { $ node -> getContents ( ) -> addRoute ( $ route , $ parameterIndexNameMap ) ; return ; } $ childSegmentMatcher = $ this -> getMatcher ( \ array_shift ( $ segments ) , $ parameterIndexNameMap ) ; if ( $ node -> getContents ( ) -> hasChildFor ( $ childSegmentMatcher ) ) { $ child = $ node -> getContents ( ) -> getChild ( $ childSegmentMatcher ) ; } else { $ child = new RouteTreeNode ( [ $ segmentDepth => $ childSegmentMatcher ] , \ count ( $ segments ) === 0 ? new MatchedRouteDataMap ( ) : new ChildrenNodeCollection ( ) ) ; $ node -> getContents ( ) -> addChild ( $ child ) ; } $ this -> addRouteToNode ( $ child , $ route , $ segments , $ segmentDepth + 1 , $ parameterIndexNameMap ) ; }
Adds a route to the node tree.

@param \Viserio\Component\Routing\TreeGenerator\RouteTreeNode $node
@param \Viserio\Component\Contract\Routing\Route              $route
@param array                                                  $segments
@param int                                                    $segmentDepth
@param array                                                  $parameterIndexNameMap

@throws \Viserio\Component\Contract\Routing\Exception\RuntimeException

@return void
Adds a route to the node tree .