RtNode::addRouteRecursively PHP Method

addRouteRecursively() private method

The recursive method powering addRouteFor(Request).
private addRouteRecursively ( &$pathParts, $index, $route ) : FindRouteResult
return FindRouteResult
    private function addRouteRecursively(&$pathParts, $index, $route)
    {
        // Base Case
        if ($index < 0) {
            foreach ($route->methods as $method) {
                if (isset($this->m[$method])) {
                    Library::import('recess.framework.routing.DuplicateRouteException');
                    throw new DuplicateRouteException($method . ' ' . str_replace('//', '/', $route->path), $route->fileDefined, $route->lineDefined);
                }
                $this->m[$method] = new Rt($route);
            }
            return;
        }
        $nextPart = $pathParts[$index];
        if ($nextPart[0] != '$') {
            $childrenArray =& $this->s;
            $nextKey = $nextPart;
            $isParam = false;
        } else {
            $childrenArray =& $this->p;
            $nextKey = substr($nextPart, 1);
            $isParam = true;
        }
        if (!isset($childrenArray[$nextKey])) {
            $child = new RtNode();
            if ($isParam) {
                $child->c = $nextKey;
            }
            $childrenArray[$nextKey] = $child;
        } else {
            $child = $childrenArray[$nextKey];
        }
        $child->addRouteRecursively($pathParts, $index - 1, $route);
    }