/** * 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(); }
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(); }
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); }
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()); } }
/** * {@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; }