Merges with other router.

@param RouterInterface $source The data source

@return null|array If the source was passed returns
null, source data otherwise
517689
public function merge(RouterInterface $source = null)
    {
        if (null == $source) {
            return [
                $this->routes,
                $this->defaultParams,
            ];
        }
        list($routes, $params) = $source->merge();

        $this->routes        = array_merge($this->routes, $routes);
        $this->defaultParams = array_merge($this->defaultParams, $params);
    }
803631
public function merge(self $router) {
        if ($this->running) {
            throw new \Error("Cannot merge routers after the server has started");
        }

        foreach ($router->routes as $route) {
            $route[1] = \ltrim($router->prefix, "/") . $route[1];
            $route[2] = Middleware\stack($route[2], ...$router->middlewares);
            $this->routes[] = $route;
        }

        $this->observers->addAll($router->observers);
    }
832514
protected function mergeOldRoutes($version)
    {
        if (! isset($this->oldRoutes)) {
            $this->oldRoutes = $this->router->getRoutes();
        }

        if (! isset($this->mergedRoutes[$version])) {
            $this->mergedRoutes[$version] = $this->routes[$version];

            foreach ($this->oldRoutes as $route) {
                $this->mergedRoutes[$version]->add($route);
            }
        }

        return $this->mergedRoutes[$version];
    }
454544
public function setRoute(RouteInterface $route): RouterInterface
    {
        $regexp = $route->getRegexp();
        $this->_routes[$regexp] = $route;
        return $this;
    }
745998
public function map(Router $router)
    {
        /** @var Tenant $tenant */
        $tenant = $this->app->make('auth.tenant');
        $router->group(
            ['namespace' => $this->namespace],
            function ($router) use ($tenant) {
                $tries = ['routes'];

                if ($tenant->getTenantOwner() instanceof DomainAwareTenantParticipant) {
                    array_unshift($tries, $tenant->getTenantOwner()->getDomain());
                }
                if ($tenant->getTenantCreator() instanceof DomainAwareTenantParticipant) {
                    array_unshift($tries, $tenant->getTenantCreator()->getDomain());
                }

                foreach ($tries as $file) {
                    $path = app_path(sprintf('Http/%s.php', $file));
                    if (file_exists($path)) {
                        require_once $path;
                        return;
                    }
                }

                throw new \RuntimeException('No routes found in: ' . implode(', ', $tries));
            }
        );
    }
1334004
public function joinToSql(string $source = null): array
    {
        $sql = $params = [];

        foreach ($this->join as $join) {
            $join = $this->prepareJoin($join);

            if ($source != $join['source']) {
                continue;
            }

            $sqlPart = ($join['type'] ? $join['type'] . ' ' : '') . 'JOIN ' . $join['table'];

            $join['alias'] && $sqlPart .= ' AS ' . $join['alias'];

            $join['on'] && $sqlPart .= ' ON ' . $join['on'];

            $params = array_merge($params, $join['params']);

            $sql[] = $sqlPart;
        }

        $sql = implode(' ', $sql);

        return [$sql, $params];
    }
1352529
private function getRequestAdapter($source)
    {
        if ($source instanceof RequestAdapter) {
            return $source;
        } elseif ($source instanceof ServerRequestInterface) {
            return new Psr7RequestAdapter($source);
        } elseif (is_array($source)) {
            return new SuperglobalRequestAdapter($source);
        }

        throw new \InvalidArgumentException("Unknown IP source.");
    }
1300044
public function loadRouteCollection($source = null)
    {
        $collection = new RouteCollection();

        $routes = $this->loadResource($source);

        foreach ($routes as $name => $route) {
            $collection->add($name, $this->parseRoute($route));
        }

        return $collection;
    }
536927
protected function dispatchRouterRoute(
        ServerRequestInterface $request,
        RouterInterface $router
    ) : ServerRequestInterface {
        $routeInfo = $router->dispatch($request);
        if ($routeInfo[0] === Dispatcher::FOUND) {
            $routeArguments = [];
            foreach ($routeInfo[2] as $k => $v) {
                $routeArguments[$k] = urldecode($v);
            }

            $route = $router->getRouteByIdentifier($routeInfo[1]);
            $route->prepare($request, $routeArguments);
            /**
             * Add route to request to allow handler or other access route
             */
            $request = $request->withAttribute('route', $route);
        }

        $routeInfo['request'] = [$request->getMethod(), (string) $request->getUri()];
        return $request->withAttribute('routeInfo', $routeInfo);
    }
1276950
protected function merge($target, $source)
    {
        if ($source === null) {
            return $target;
        }

        return call_user_func($this->merge, $target, $source);
    }
1043564
protected function determineLoaderFromClass($source): LoaderInterface
    {
        foreach ($this->loaders as $key => $loader) {
            if (class_exists($key) && is_a($source, $key)) {
                return $loader;
            }
        }

        $desc = get_class($source) . ' ' . gettype($source);
        throw new NoLoaderException("Don't know how to load configuration from $desc");
    }
902009
protected function mergeReferences(RootPackageInterface $root)
    {
        // Merge source reference information for merged packages.
        // @see RootPackageLoader::load
        $references = array();
        $unwrapped = $this->unwrapIfNeeded($root, 'setReferences');
        foreach (array('require', 'require-dev') as $linkType) {
            $linkInfo = BasePackage::$supportedLinkTypes[$linkType];
            $method = 'get'.ucfirst($linkInfo['method']);
            $links = array();
            foreach ($unwrapped->$method() as $link) {
                $links[$link->getTarget()] = $link->getConstraint()->getPrettyString();
            }
            $references = $this->extractReferences($links, $references);
        }
        $unwrapped->setReferences($references);
    }
398470
public function models(Source $source = null) {
		if ($source) {
			$this->applyStrategy($source);
		}
		return $this->_models;
	}
827763
protected function getMerger(): MergerInterface
    {
        if (! $this->merger instanceof MergerInterface) {
            $this->merger = new RecursiveMerger();
        }

        return $this->merger;
    }
1348049
public function addResourceRoute(RouteInterface $resourceRoute
    ): RouteInterface
    {
        $resourceRoute->setIdentifier('route' . $this->routeCounter++);
        // Add route
        $this->routes[$resourceRoute->getIdentifier()] = $resourceRoute;

        return $resourceRoute;
    }
488959
protected function mergeOldRoutes($version)
    {
        if (! isset($this->oldRoutes)) {
            $this->oldRoutes = $this->app->router->getRoutes();
        }
        if (! isset($this->mergedRoutes[$version])) {
            $this->mergedRoutes[$version] = $this->routes[$version];
            foreach ($this->oldRoutes as $route) {
                $this->mergedRoutes[$version]->addRoute($route['method'], $route['uri'], $route['action']);
            }
        }

        return $this->mergedRoutes[$version];
    }
666078
protected function _findWebRoot($source)
    {
        $webRootDir = Configure::read('App.webroot');
        $webRoot    = APP_ROOT . DS . $webRootDir . DS;

        list ($plugin, $source) = $this->_View->pluginSplit($source);
        if ($plugin !== null && Plugin::loaded($plugin)) {
            $webRoot = Plugin::path($plugin) . $webRootDir . DS;
        }

        return [FS::clean($webRoot, '/'), $source];
    }