Exemple #1
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;