public function testAdd() { $routeCollection = new RouteCollection(); $routeCollection->add('routeA', $this->routes['routeA']); $this->assertEquals(['routeA' => $this->routes['routeA']], $this->readProperty($routeCollection, 'routes')); $routeCollection->add('routeB', $this->routes['routeB']); $this->assertEquals(['routeA' => $this->routes['routeA'], 'routeB' => $this->routes['routeB']], $this->readProperty($routeCollection, 'routes')); }
/** * @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; }