Merge the old application routes with the API routes.

@param string $version

@return array
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];
    }
1128253
public function migrationClass($group, $version)
    {
        $versions = array_get($this->migrations, $group, []);

        return array_get($versions, $version, null);
    }
1232184
public static function replaceLinks($version, $content)
    {
        $content = str_replace('{{version}}', $version, $content);

        $content = str_replace('{{route}}', trim(config('larecipe.docs.route'), '/'), $content);

        return $content;
    }
698301
protected function _getVersionPath($path, $version)
    {
        $type = $this->_getVersionType($version);

        if ($type == 'latest') {
            $version = 'latest';
        }

        $availableVersions = $this->_getAvailableVersions($path, $version);
        if (empty($availableVersions)) {
            throw new Zend_Loader_Exception('No valid ZF installations discovered');
        }

        $matchedVersion = array_pop($availableVersions);
        return $matchedVersion;
    }
891087
public function getPreset($application, $version, array $options = null)
    {
        $presets = [];
        foreach ($this->presets as $preset) {
            if ($preset['application'] === $application
                && $this->matchVersion($version, $preset)
                && $this->matchOptions($options, $preset)
            ) {
                $presets[] = $preset['backup'];
            }
        }

        if (0 === count($presets)) {
            return [];
        }
        if (1 === count($presets)) {
            return $presets[0];
        }

        return call_user_func_array('array_merge', $presets);
    }
1070977
public function show(string $version, array $params = [])
    {
        $path = $this->buildVersionsPath($version);

        return $this->get($path, $params);
    }
1140329
public function addRoute(array $methods, array $versions, $uri, $action)
    {
        $this->createRouteCollections($versions);

        $route = new Route($methods, $uri, $action);
        $route->where($action['where']);

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

        return $route;
    }
155602
public static function formatVersion($version)
    {
        return sprintf('%s-%s-%s %s:%s:%s',
            substr($version, 0, 4),
            substr($version, 4, 2),
            substr($version, 6, 2),
            substr($version, 8, 2),
            substr($version, 10, 2),
            substr($version, 12, 2)
        );
    }
676738
public static function getStaticMaps( string $locale = 'en_US', string $version = null ) : array
	{
		$url = self::getStaticDataFileUrl(self::STATIC_MAPS, null, $locale, $version);
		return self::loadStaticData($url);
	}
1211450
public function withProtocolVersion($version)
    {
        $request = clone $this;
        if (method_exists($request, 'setProtocolVersion')) {
            $request->setProtocolVersion($version);
        } else {
            $request->server->set('SERVER_PROTOCOL', $version);
        }

        return $request;
    }
858294
protected function getPackageKeyFromMigrationVersion(Version $version)
    {
        $sortedAvailablePackages = $this->packageManager->getAvailablePackages();
        usort($sortedAvailablePackages, function (PackageInterface $packageOne, PackageInterface $packageTwo) {
            return strlen($packageTwo->getPackagePath()) - strlen($packageOne->getPackagePath());
        });

        $reflectedClass = new \ReflectionClass($version->getMigration());
        $classPathAndFilename = Files::getUnixStylePath($reflectedClass->getFileName());

        /** @var $package PackageInterface */
        foreach ($sortedAvailablePackages as $package) {
            $packagePath = Files::getUnixStylePath($package->getPackagePath());
            if (strpos($classPathAndFilename, $packagePath) === 0) {
                return $package->getPackageKey();
            }
        }

        return '';
    }
14394
protected static function splitUrlVersion($version)
    {
        $pos = strpos($version, '#');

        // number version or empty version
        if (false !== $pos) {
            $url = substr($version, 0, $pos);
            $version = substr($version, $pos);
        } else {
            $url = $version;
            $version = '#';
        }

        return array($url, $version);
    }
839847
private function buildVersion(SimpleXMLElement $version): array
    {
        $apis = [];
        $guides = [];
        foreach ($version->children() as $child) {
            switch ($child->getName()) {
                case 'api':
                    $apis[] = $this->buildApi($child);
                    break;
                case 'guide':
                    $guides[] = $this->buildGuide($child);
                    break;
                default:
                    break;
            }
        }

        $version = [
            'folder' => (string) $version->folder,
        ];

        if (count($apis) > 0) {
            $version['api'] = $apis;
        }

        if (count($guides) > 0) {
            $version['guide'] = $guides;
        }

        return $version;
    }
1341841
public function getItineraryParams($from, $version)
    {
        $from = self::getItineraryURIWithVersion($from, $version);

        // Find itinerary
        try {
            $params = $this->getItinerariesRouter()->match($from);
        } catch (InternalRouterResourceNotFound $exception) {
            throw new InternalRouterResourceNotFound("Itinerary not found for uri: $from");
        }
        if (empty($params) || !array_key_exists(InternalRouter::KEY_ITINERARY, $params)) {
            throw new InternalRouterResourceNotFound("Itinerary not found for uri: $from");
        }

        $itinerary = $params[InternalRouter::KEY_ITINERARY];
        if (!$itinerary instanceof Itinerary) {
            throw new \Exception("Error trying to get itinerary for '$from', the itinerary must be an instance of Itinerary.");
        }

        return $params;
    }
569723
public function dispatch(Request $request, $version)
    {
        if (! isset($this->routes[$version])) {
            throw new UnknownVersionException();
        }

        $routes = $this->mergeOldRoutes($version);

        $this->router->setRoutes($routes);

        $router = clone $this->router;

        $response = $router->dispatch($request);

        unset($router);

        return $response;
    }
1216637
public function getIndex($version)
    {
        return $this->cache->remember(function() use($version) {
            $path = base_path(config('larecipe.docs.path').'/'.$version.'/index.md');

            if ($this->files->exists($path)) {
                $parsedContent = $this->parse($this->files->get($path));

                return $this->replaceLinks($version, $parsedContent);
            }

            return null;
        }, 'larecipe.docs.'.$version.'.index');
    }
27332
protected static function cleanVersion($version, array $matches)
    {
        $end = substr($version, \strlen($matches[1][0][0]));
        $version = $matches[1][0][0].'-';

        $matches = array();
        if (preg_match('/^(\-|\+)/', $end, $matches)) {
            $end = substr($end, 1);
        }

        $matches = array();
        preg_match('/^[a-z]+/', $end, $matches);
        $type = isset($matches[0]) ? VersionParser::normalizeStability($matches[0]) : null;
        $end = substr($end, \strlen($type));

        return array($type, $version, $end);
    }