示例#1
0
 /**
  * Load up our routes.
  *
  * @param string $path
  *
  * @return \Symfony\Component\Routing\RouteCollection
  */
 protected function loadSymfonyRoutes($path)
 {
     if ($this->routes === null) {
         $loader = new YamlFileLoader(new FileLocator(array(dirname($path))));
         $loader->setDefaults(array('_module' => $this->getName()));
         $routesCollection = $loader->load(pathinfo($path, PATHINFO_FILENAME) . '.' . pathinfo($path, PATHINFO_EXTENSION));
         $this->routes = $routesCollection;
     }
     return $this->routes;
 }
 public function testLoadWithResource()
 {
     $loader = new YamlFileLoader(new FileLocator(array(__DIR__ . '/../Fixtures')));
     $routeCollection = $loader->load('validresource.yml');
     $routes = $routeCollection->all();
     $this->assertCount(3, $routes, 'Three routes are loaded');
     $this->assertContainsOnly('Symfony\\Component\\Routing\\Route', $routes);
     foreach ($routes as $route) {
         $this->assertSame('/{foo}/blog/{slug}', $route->getPath());
         $this->assertSame('123', $route->getDefault('foo'));
         $this->assertSame('\\d+', $route->getRequirement('foo'));
         $this->assertSame('bar', $route->getOption('foo'));
         $this->assertSame('', $route->getHost());
         $this->assertSame('context.getMethod() == "POST"', $route->getCondition());
     }
 }