public function testAddCollection()
 {
     $routeCollectionA = new RouteCollection(['routeA' => $this->routes['routeA'], 'routeB' => $this->routes['routeB']]);
     $routeCollectionB = new RouteCollection(['routeC' => $this->routes['routeC']]);
     $routeCollectionA->addCollection($routeCollectionB);
     $this->assertEquals($this->routes, $this->readProperty($routeCollectionA, 'routes'));
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function generate($routeName, array $parameters = [], $tokenSeparator)
 {
     $route = $this->collection->get($routeName);
     if (false === $route) {
         throw new ResourceNotFoundException(sprintf('Route %s not exists in [%s]', $routeName, implode(', ', array_keys($this->collection->all()))));
     }
     $tokens = $this->tokenizer->tokenize($route, $tokenSeparator);
     return $this->generateFromTokens($route, $tokens, $parameters, $tokenSeparator);
 }
 /**
  * @param RouteCollection $collection
  *
  * @return RouteCollection
  */
 public function load()
 {
     if ($cachedCollection = $this->cache->fetch('collection.' . $this->type)) {
         $this->collection->addCollection($cachedCollection);
         return $this->collection;
     }
     $loaderResolver = new LoaderResolver($this->loaders);
     $delegatingLoader = new DelegatingLoader($loaderResolver);
     foreach ($this->resources as $resource) {
         $this->collection->addCollection($delegatingLoader->load($resource));
     }
     $this->cache->save('collection.' . $this->type, $this->collection);
     return $this->collection;
 }
 /**
  * @param string $resource
  * @param null   $type
  *
  * @return RouteCollection
  */
 public function load($resource, $type = null)
 {
     $resource = parent::load($resource, $type);
     if (null === $this->yamlParser) {
         $this->yamlParser = new Parser();
     }
     $config = $this->yamlParser->parse(file_get_contents($resource));
     $routeCollection = new RouteCollection();
     if (!is_array($config)) {
         throw new \InvalidArgumentException('Invalid configuration');
     }
     foreach ($config as $routeName => $routeConfig) {
         $this->validate($routeConfig, $routeName, $resource);
         $handler = $routeConfig['handler'];
         $routeCollection->add($routeName, new Route($routeConfig['channel'], $handler['callback'], isset($handler['args']) ? $handler['args'] : [], isset($routeConfig['requirements']) ? $routeConfig['requirements'] : []));
     }
     return $routeCollection;
 }