Example #1
0
 public function testMatchMapWhenQueryParametersArePresent()
 {
     $route = new Route("/2008-08-01/Accounts/:id/IncomingPhoneNumbers");
     $route->setMapClass('IncomingPhoneNumbers')->setMapMethod('list');
     $route->addDynamicElement(':id', ':id');
     $result = $route->matchMap('/2008-08-01/Accounts/1/IncomingPhoneNumbers?a=1&b=2');
     $this->assertTrue($result);
 }
// read the config file
// require the libraries which we will be using
require_once INCLUDE_DIR . '/PageError/PageError.php';
require_once INCLUDE_DIR . '/php-router/php-router.php';
require_once INCLUDE_DIR . '/Twig/lib/Twig/Autoloader.php';
// register the Twig Autoloader
Twig_Autoloader::register();
// Create a new instance of Router
$router = new Router();
// Get an instance of Dispatcher
$dispatcher = new Dispatcher();
$dispatcher->setSuffix('Controller');
$dispatcher->setClassPath(CONTROLLER_DIR);
// Set up your default route:
$default_route = new Route('/');
$default_route->setMapClass('default')->setMapMethod('index');
$router->addRoute('default', $default_route);
$url = urldecode($_SERVER['REQUEST_URI']);
try {
    $found_route = $router->findRoute($url);
    $dispatcher->dispatch($found_route);
} catch (RouteNotFoundException $e) {
    PageError::show('404', $url);
} catch (badClassNameException $e) {
    PageError::show('400', $url);
} catch (classFileNotFoundException $e) {
    PageError::show('500', $url);
} catch (classNameNotFoundException $e) {
    PageError::show('500', $url);
} catch (classMethodNotFoundException $e) {
    PageError::show('500', $url);
Example #3
0
 public function testQueryParameters()
 {
     $router = new Router();
     $route = new Route("/2008-08-01/Accounts/:id/IncomingPhoneNumbers");
     $route->setMapClass('IncomingPhoneNumbers')->setMapMethod('list');
     $route->addDynamicElement(':id', ':id');
     $router->addRoute('test', $route);
     $found = $router->findRoute('/2008-08-01/Accounts/1/IncomingPhoneNumbers?a=1&b=2');
     $this->assertSame($found, $route);
 }