mirror of
https://github.com/dannyvankooten/AltoRouter.git
synced 2025-08-03 15:07:43 +02:00
Use instance methods to set basePath and matchTypes
renamed addMatchType to addMatchTypes
This commit is contained in:
@@ -22,8 +22,8 @@ class AltoRouter {
|
|||||||
* @param array $matchTypes
|
* @param array $matchTypes
|
||||||
*/
|
*/
|
||||||
public function __construct( $routes = array(), $basePath = '', $matchTypes = array() ) {
|
public function __construct( $routes = array(), $basePath = '', $matchTypes = array() ) {
|
||||||
$this->basePath = $basePath;
|
$this->setBasePath($basePath);
|
||||||
$this->matchTypes = array_merge($this->matchTypes, $matchTypes);
|
$this->addMatchTypes($matchTypes);
|
||||||
|
|
||||||
foreach( $routes as $route ) {
|
foreach( $routes as $route ) {
|
||||||
call_user_func_array(array($this,'map'),$route);
|
call_user_func_array(array($this,'map'),$route);
|
||||||
@@ -39,11 +39,11 @@ class AltoRouter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new named match type. It uses array_merge so keys can be overwritten.
|
* Add named match types. It uses array_merge so keys can be overwritten.
|
||||||
*
|
*
|
||||||
* @param array $matchType The key is the name and the value is the regex.
|
* @param array $matchTypes The key is the name and the value is the regex.
|
||||||
*/
|
*/
|
||||||
public function addMatchType($matchTypes) {
|
public function addMatchTypes($matchTypes) {
|
||||||
$this->matchTypes = array_merge($this->matchTypes, $matchTypes);
|
$this->matchTypes = array_merge($this->matchTypes, $matchTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -268,7 +268,7 @@ class AltoRouterTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testMatchWithCustomNamedRegex()
|
public function testMatchWithCustomNamedRegex()
|
||||||
{
|
{
|
||||||
$this->router->addMatchType(array('cId' => '[a-zA-Z]{2}[0-9](?:_[0-9]++)?'));
|
$this->router->addMatchTypes(array('cId' => '[a-zA-Z]{2}[0-9](?:_[0-9]++)?'));
|
||||||
$this->router->map('GET', '/bar/[cId:customId]', 'bar_action', 'bar_route');
|
$this->router->map('GET', '/bar/[cId:customId]', 'bar_action', 'bar_route');
|
||||||
|
|
||||||
$this->assertEquals(array(
|
$this->assertEquals(array(
|
||||||
|
Reference in New Issue
Block a user