protected function mergeRoutesWithSubRoutes(array $routesConfiguration)
    {
        $mergedRoutesConfiguration = [];
        foreach ($routesConfiguration as $routeConfiguration) {
            if (!isset($routeConfiguration['subRoutes'])) {
                $mergedRoutesConfiguration[] = $routeConfiguration;
                continue;
            }
            $mergedSubRoutesConfiguration = [$routeConfiguration];
            foreach ($routeConfiguration['subRoutes'] as $subRouteKey => $subRouteOptions) {
                if (!isset($subRouteOptions['package'])) {
                    throw new Exception\ParseErrorException(sprintf('Missing package configuration for SubRoute in Route "%s".', (isset($routeConfiguration['name']) ? $routeConfiguration['name'] : 'unnamed Route')), 1318414040);
                }
                if (!isset($this->packages[$subRouteOptions['package']])) {
                    throw new Exception\ParseErrorException(sprintf('The SubRoute Package "%s" referenced in Route "%s" is not available.', $subRouteOptions['package'], (isset($routeConfiguration['name']) ? $routeConfiguration['name'] : 'unnamed Route')), 1318414040);
                }
                /** @var $package PackageInterface */
                $package = $this->packages[$subRouteOptions['package']];
                $subRouteFilename = 'Routes';
                if (isset($subRouteOptions['suffix'])) {
                    $subRouteFilename .= '.' . $subRouteOptions['suffix'];
                }
                $subRouteConfiguration = [];
                foreach (array_reverse($this->orderedListOfContextNames) as $contextName) {
                    $subRouteFilePathAndName = $package->getConfigurationPath() . $contextName . '/' . $subRouteFilename;
                    $subRouteConfiguration = array_merge($subRouteConfiguration, $this->configurationSource->load($subRouteFilePathAndName));
                }
                $subRouteFilePathAndName = $package->getConfigurationPath() . $subRouteFilename;
                $subRouteConfiguration = array_merge($subRouteConfiguration, $this->configurationSource->load($subRouteFilePathAndName));
                if ($this->subRoutesRecursionLevel > self::MAXIMUM_SUBROUTE_RECURSIONS) {
                    throw new Exception\RecursionException(sprintf('Recursion level of SubRoutes exceed ' . self::MAXIMUM_SUBROUTE_RECURSIONS . ', probably because of a circular reference. Last successfully loaded route configuration is "%s".', $subRouteFilePathAndName), 1361535753);
                }

                $this->subRoutesRecursionLevel++;
                $subRouteConfiguration = $this->mergeRoutesWithSubRoutes($subRouteConfiguration);
                $this->subRoutesRecursionLevel--;
                $mergedSubRoutesConfiguration = $this->buildSubRouteConfigurations($mergedSubRoutesConfiguration, $subRouteConfiguration, $subRouteKey, $subRouteOptions);
            }
            $mergedRoutesConfiguration = array_merge($mergedRoutesConfiguration, $mergedSubRoutesConfiguration);
        }

        return $mergedRoutesConfiguration;
    }
protected function mergeRoutesWithSubRoutes(array $routesConfiguration)
    {
        $mergedRoutesConfiguration = [];
        foreach ($routesConfiguration as $routeConfiguration) {
            if (!isset($routeConfiguration['subRoutes'])) {
                $mergedRoutesConfiguration[] = $routeConfiguration;
                continue;
            }
            $mergedSubRoutesConfiguration = [$routeConfiguration];
            foreach ($routeConfiguration['subRoutes'] as $subRouteKey => $subRouteOptions) {
                if (!isset($subRouteOptions['package'])) {
                    throw new Exception\ParseErrorException(sprintf('Missing package configuration for SubRoute in Route "%s".', (isset($routeConfiguration['name']) ? $routeConfiguration['name'] : 'unnamed Route')), 1318414040);
                }
                if (!isset($this->packages[$subRouteOptions['package']])) {
                    throw new Exception\ParseErrorException(sprintf('The SubRoute Package "%s" referenced in Route "%s" is not available.', $subRouteOptions['package'], (isset($routeConfiguration['name']) ? $routeConfiguration['name'] : 'unnamed Route')), 1318414040);
                }
                /** @var $package PackageInterface */
                $package = $this->packages[$subRouteOptions['package']];
                $subRouteFilename = 'Routes';
                if (isset($subRouteOptions['suffix'])) {
                    $subRouteFilename .= '.' . $subRouteOptions['suffix'];
                }
                $subRouteConfiguration = [];
                foreach (array_reverse($this->orderedListOfContextNames) as $contextName) {
                    $subRouteFilePathAndName = $package->getConfigurationPath() . $contextName . '/' . $subRouteFilename;
                    $subRouteConfiguration = array_merge($subRouteConfiguration, $this->configurationSource->load($subRouteFilePathAndName));
                }
                $subRouteFilePathAndName = $package->getConfigurationPath() . $subRouteFilename;
                $subRouteConfiguration = array_merge($subRouteConfiguration, $this->configurationSource->load($subRouteFilePathAndName));
                if ($this->subRoutesRecursionLevel > self::MAXIMUM_SUBROUTE_RECURSIONS) {
                    throw new Exception\RecursionException(sprintf('Recursion level of SubRoutes exceed ' . self::MAXIMUM_SUBROUTE_RECURSIONS . ', probably because of a circular reference. Last successfully loaded route configuration is "%s".', $subRouteFilePathAndName), 1361535753);
                }

                $this->subRoutesRecursionLevel++;
                $subRouteConfiguration = $this->mergeRoutesWithSubRoutes($subRouteConfiguration);
                $this->subRoutesRecursionLevel--;
                $mergedSubRoutesConfiguration = $this->buildSubRouteConfigurations($mergedSubRoutesConfiguration, $subRouteConfiguration, $subRouteKey, $subRouteOptions);
            }
            $mergedRoutesConfiguration = array_merge($mergedRoutesConfiguration, $mergedSubRoutesConfiguration);
        }

        return $mergedRoutesConfiguration;
    }
protected function mergeRoutesWithSubRoutes ( array $ routesConfiguration ) { $ mergedRoutesConfiguration = [ ] ; foreach ( $ routesConfiguration as $ routeConfiguration ) { if ( ! isset ( $ routeConfiguration [ 'subRoutes' ] ) ) { $ mergedRoutesConfiguration [ ] = $ routeConfiguration ; continue ; } $ mergedSubRoutesConfiguration = [ $ routeConfiguration ] ; foreach ( $ routeConfiguration [ 'subRoutes' ] as $ subRouteKey => $ subRouteOptions ) { if ( ! isset ( $ subRouteOptions [ 'package' ] ) ) { throw new Exception \ ParseErrorException ( sprintf ( 'Missing package configuration for SubRoute in Route "%s".' , ( isset ( $ routeConfiguration [ 'name' ] ) ? $ routeConfiguration [ 'name' ] : 'unnamed Route' ) ) , 1318414040 ) ; } if ( ! isset ( $ this -> packages [ $ subRouteOptions [ 'package' ] ] ) ) { throw new Exception \ ParseErrorException ( sprintf ( 'The SubRoute Package "%s" referenced in Route "%s" is not available.' , $ subRouteOptions [ 'package' ] , ( isset ( $ routeConfiguration [ 'name' ] ) ? $ routeConfiguration [ 'name' ] : 'unnamed Route' ) ) , 1318414040 ) ; } /** @var $package PackageInterface */ $ package = $ this -> packages [ $ subRouteOptions [ 'package' ] ] ; $ subRouteFilename = 'Routes' ; if ( isset ( $ subRouteOptions [ 'suffix' ] ) ) { $ subRouteFilename .= '.' . $ subRouteOptions [ 'suffix' ] ; } $ subRouteConfiguration = [ ] ; foreach ( array_reverse ( $ this -> orderedListOfContextNames ) as $ contextName ) { $ subRouteFilePathAndName = $ package -> getConfigurationPath ( ) . $ contextName . '/' . $ subRouteFilename ; $ subRouteConfiguration = array_merge ( $ subRouteConfiguration , $ this -> configurationSource -> load ( $ subRouteFilePathAndName ) ) ; } $ subRouteFilePathAndName = $ package -> getConfigurationPath ( ) . $ subRouteFilename ; $ subRouteConfiguration = array_merge ( $ subRouteConfiguration , $ this -> configurationSource -> load ( $ subRouteFilePathAndName ) ) ; if ( $ this -> subRoutesRecursionLevel > self :: MAXIMUM_SUBROUTE_RECURSIONS ) { throw new Exception \ RecursionException ( sprintf ( 'Recursion level of SubRoutes exceed ' . self :: MAXIMUM_SUBROUTE_RECURSIONS . ', probably because of a circular reference. Last successfully loaded route configuration is "%s".' , $ subRouteFilePathAndName ) , 1361535753 ) ; } $ this -> subRoutesRecursionLevel ++ ; $ subRouteConfiguration = $ this -> mergeRoutesWithSubRoutes ( $ subRouteConfiguration ) ; $ this -> subRoutesRecursionLevel -- ; $ mergedSubRoutesConfiguration = $ this -> buildSubRouteConfigurations ( $ mergedSubRoutesConfiguration , $ subRouteConfiguration , $ subRouteKey , $ subRouteOptions ) ; } $ mergedRoutesConfiguration = array_merge ( $ mergedRoutesConfiguration , $ mergedSubRoutesConfiguration ) ; } return $ mergedRoutesConfiguration ; }
Loads specified sub routes and builds composite routes.

@param array $routesConfiguration
@return array
@throws Exception\ParseErrorException
@throws Exception\RecursionException
Loads specified sub routes and builds composite routes .