public function testLoad3() { $router = $this->getMock('Packfire\\Router\\RouterInterface'); $router->expects($this->exactly(2))->method('add'); $factory = new ConfigFactory(); $config = $factory->load(__DIR__ . '/sampleRoutes.yml'); $loader = new ConfigLoader($config); $resultRouter = $loader->load($router); $this->assertInstanceOf('Packfire\\Router\\RouterInterface', $resultRouter); $this->assertEquals($router, $resultRouter); }
/** * Load the configuration to a router * @param Packfire\Router\RouterInterface $router (optional) Provide a specific router to load the configuration into * @return Packfire\Router\RouterInterface Returns a router loaded with the configuration */ public function load(RouterInterface $router = null) { if (!$router) { if (isset($this->container['Packfire\\Router\\RouterInterface'])) { $router = $this->container['Packfire\\Router\\RouterInterface']; } else { $router = $this->container->instantiate('Packfire\\Router\\Router'); } } $factory = new ConfigFactory(); $config = $factory->load($this->file); $routes = $config->get('routes'); if ($routes) { foreach ($routes as $name => $route) { $router->add($name, $route); } } return $router; }