public function testDecorate()
 {
     $collection = new RouteCollection();
     $collection->get('no-tokens', '/no-tokens', '');
     $collection->get('token-digit', '/token-digit/{token}', '')->addRule('token', 'digit');
     $collection->compile();
     $creator = new MyRouteCreator($collection);
     $this->assertEquals('/before/no-tokens/after', $creator->create('no-tokens'));
     $this->assertEquals('/before/token-digit/1/after', $creator->create('token-digit', ['token' => '1']));
 }
 /**
  * Create two collections, merge it and checks if base collection
  * has two routes.
  */
 public function testMerge()
 {
     $this->collection->get('current', '/current', 'actionCurrent');
     $newCollection = new RouteCollection();
     $newCollection->get('new', '/', 'action');
     $this->collection->mergeWith($newCollection);
     $routes = $this->collection->all();
     $this->assertCount(2, $routes);
     $this->assertArrayHasKey('0', $routes);
     $this->assertArrayHasKey('1', $routes);
     $this->assertEquals('current', $routes[0]->getName());
     $this->assertEquals('/current', $routes[0]->getSourceRoute());
     $this->assertEquals('new', $routes[1]->getName());
     $this->assertEquals('/', $routes[1]->getSourceRoute());
 }
Exemple #3
0
// Optional argument in path
$collection->add(new Route('/{argument?}', 'Controller:action'));

// Optional argument in path II
$collection->add(new Route('/{argument}/{argument2?}', 'Controller:action'));

// Defined arguments
$collection->add(new Route('/{argument}/{argument2}', 'Controller:action'))
    ->setRules(['argument1' => '\d', 'argument2' => '[a-z]+']);

// Defined argument and optional defined argument
$collection->add(new Route('/{argumentWith-MANY_chars12365dD}/{argument2?}', 'Controller:action'))
    ->setRules(['argument1' => '\d', 'argument2' => '[a-z]+']);*/
// Full options route
$collection->add(new Route('full-option', '/full/{argument1}/{argument2}', 'Controller:action'))->setRules(['argument2' => 'word', 'argument1' => 'digit'])->setMethods(['POST'])->addMethod('GET');
$collection->get('homepage', '/', 'Homepage:Homepage');
$collection->group('blog.', '/blog', function ($collection) {
    $collection->get('homepage', '', function ($request, $response) {
    });
    $collection->get('show', '/{id}', 'Blog:show');
    $collection->get('delete', '/delete/{id}', 'Blog:delete');
});
$collection->get('asd', '/path-to/{digit}/asd/{alnum}/{number}', 'Homepage:Homepage');
$compiler = new RouteDefinitionCompiler();
//$compiler->addPredefinedRule('alias', '[a-zA-Z0-9\-]+');
$collection->compileWithCompiler($compiler);
$creator = new RouteCreator($collection);
var_dump($creator->create('full-option', ['argument2' => 'alias', 'argument1' => 1]));
/*$exported = $collection->export();
$collection2 = new RouteCollection;
$collection2->importFromArray($exported);