1
0
mirror of https://github.com/dannyvankooten/AltoRouter.git synced 2025-08-09 01:46:34 +02:00

Added method for setting new and modifying existing named match types.

It's also possible to set these from the constructor.

$router->generate() is now possible with custom regex matches.
This commit is contained in:
Oskar Adin
2014-01-08 12:27:35 +01:00
parent d878579e02
commit 8a19056553
2 changed files with 51 additions and 13 deletions

View File

@@ -3,7 +3,7 @@
require 'AltoRouter.php';
class AltoRouterDebug extends AltoRouter{
public function getNamedRoutes(){
return $this->namedRoutes;
}
@@ -15,6 +15,7 @@ class AltoRouterDebug extends AltoRouter{
public function getBasePath(){
return $this->basePath;
}
}
/**
@@ -264,4 +265,29 @@ class AltoRouterTest extends PHPUnit_Framework_TestCase
$this->assertFalse($this->router->match('/some-other-thing', 'GET'));
}
public function testMatchWithCustomNamedRegex()
{
$this->router->addMatchType(array('cId' => '[a-zA-Z]{2}[0-9](?:_[0-9]++)?'));
$this->router->map('GET', '/bar/[cId:customId]', 'bar_action', 'bar_route');
$this->assertEquals(array(
'target' => 'bar_action',
'params' => array(
'customId' => 'AB1',
),
'name' => 'bar_route'
), $this->router->match('/bar/AB1', 'GET'));
$this->assertEquals(array(
'target' => 'bar_action',
'params' => array(
'customId' => 'AB1_0123456789',
),
'name' => 'bar_route'
), $this->router->match('/bar/AB1_0123456789', 'GET'));
$this->assertFalse($this->router->match('/some-other-thing', 'GET'));
}
}