The file must return a RouteCollection instance.
Author: Fabien Potencier (fabien@symfony.com)
Inheritance: extends Symfony\Component\Config\Loader\FileLoader
 public function runTest()
 {
     $locator = new FileLocator(array(__DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "config"));
     $loader = new PhpFileLoader($locator);
     $routes = $loader->load("routing.php");
     $validator = new RouteValidator(new UrlMatcher($routes, new RequestContext("/")));
     $validator->validate();
 }
Example #2
0
 /**
  * @covers Symfony\Component\Routing\Loader\PhpFileLoader::supports
  */
 public function testSupports()
 {
     $loader = new PhpFileLoader();
     $this->assertTrue($loader->supports('foo.php'), '->supports() returns true if the resource is loadable');
     $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
     $this->assertTrue($loader->supports('foo.php', 'php'), '->supports() checks the resource type if specified');
     $this->assertFalse($loader->supports('foo.php', 'foo'), '->supports() checks the resource type if specified');
 }
Example #3
0
 /**
  * @covers Symfony\Component\Routing\Loader\PhpFileLoader::supports
  */
 public function testSupports()
 {
     $loader = new PhpFileLoader($this->getMock('Symfony\\Component\\Config\\FileLocator'));
     $this->assertTrue($loader->supports('foo.php'), '->supports() returns true if the resource is loadable');
     $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
     $this->assertTrue($loader->supports('foo.php', 'php'), '->supports() checks the resource type if specified');
     $this->assertFalse($loader->supports('foo.php', 'foo'), '->supports() checks the resource type if specified');
 }
 public function testLoadWithRoute()
 {
     $loader = new PhpFileLoader(new FileLocator(array(__DIR__ . '/../Fixtures')));
     $routeCollection = $loader->load('validpattern.php');
     $routes = $routeCollection->all();
     $this->assertEquals(1, count($routes), 'One route is loaded');
     $this->assertContainsOnly('Symfony\\Component\\Routing\\Route', $routes);
 }
 public function testThatDefiningVariableInConfigFileHasNoSideEffects()
 {
     $locator = new FileLocator(array(__DIR__ . '/../Fixtures'));
     $loader = new PhpFileLoader($locator);
     $routeCollection = $loader->load('with_define_path_variable.php');
     $resources = $routeCollection->getResources();
     $this->assertCount(1, $resources);
     $this->assertContainsOnly('Symfony\\Component\\Config\\Resource\\ResourceInterface', $resources);
     $fileResource = reset($resources);
     $this->assertSame(realpath($locator->locate('with_define_path_variable.php')), (string) $fileResource);
 }
 /**
  * Routing wrapper constructor
  */
 public function __construct()
 {
     // grab the location of the routes-file
     $routeFile = Configuration::instance()->setting('base', 'routeFile', 'routes.php');
     // tell the loader to look for said file in the approot
     $locator = new FileLocator(APPROOT);
     // create a loader for a php file that'll return an array
     $this->loader = new PhpFileLoader($locator);
     // load the actual routes from the file
     $this->routes = $this->loader->load($routeFile);
     // create a fresh context for usage later on in the lifecycle
     $this->context = new RequestContext();
 }
Example #7
0
    public function testLoadWithRoute()
    {
        $loader = new PhpFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
        $routeCollection = $loader->load('validpattern.php');
        $routes = $routeCollection->all();

        $this->assertEquals(1, count($routes), 'One route is loaded');
        $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
        $route = $routes['blog_show'];
        $this->assertEquals('/blog/{slug}', $route->getPath());
        $this->assertEquals('MyBlogBundle:Blog:show', $route->getDefault('_controller'));
        $this->assertEquals('GET', $route->getRequirement('_method'));
        $this->assertEquals('{locale}.example.com', $route->getHost());
        $this->assertEquals('RouteCompiler', $route->getOption('compiler_class'));
    }
 public function testLoadWithRoute()
 {
     $loader = new PhpFileLoader(new FileLocator(array(__DIR__ . '/../Fixtures')));
     $routeCollection = $loader->load('validpattern.php');
     $routes = $routeCollection->all();
     $this->assertCount(2, $routes, 'Two routes are loaded');
     $this->assertContainsOnly('Symfony\\Component\\Routing\\Route', $routes);
     foreach ($routes as $route) {
         $this->assertSame('/blog/{slug}', $route->getPath());
         $this->assertSame('MyBlogBundle:Blog:show', $route->getDefault('_controller'));
         $this->assertSame('{locale}.example.com', $route->getHost());
         $this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
         $this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
         $this->assertEquals(array('https'), $route->getSchemes());
     }
 }
Example #9
0
 /**
  * {@inheritdoc}
  *
  * @api
  */
 public function handle()
 {
     if (false === $this->booted) {
         $this->boot();
     }
     try {
         $request = Request::createFromGlobals();
         $this->request = $request;
         // Load in the default routes
         $default = $this->default_controller ?: $this->get_root_namespace() . "\\Controller\\PageController";
         $loader = new PhpFileLoader(new FileLocator(array(__DIR__)));
         $loader->default_controler = $default;
         $this->router->addCollection($loader->load('DefaultRoutes.php'));
         $context = new Routing\RequestContext();
         $context->fromRequest($request);
         $matcher = new Routing\Matcher\UrlMatcher($this->router, $context);
         $attributes = $matcher->match($request->getPathInfo());
         $response = $this->dispatch($attributes);
     } catch (\Exception $e) {
         $response = new Response('A fatal error occurred: ' . $e->getMessage(), 500);
     }
     return $response;
 }