dev-master
9999999-devDifferent approach for standard routing problem. Matching tree based.
MIT
The Development Requires
route routing
Wallogit.com
2017 © Pedro Peláez
Different approach for standard routing problem. Matching tree based.
Different approach for standard routing problem. Instead of using regular expressions, matching tree is built., (*1)
This library will not work with older versions of PHP. Minimal version is 5.3, (*2)
``` php use IgorCrevar\icRouter\Router; use IgorCrevar\icRouter\Route; use IgorCrevar\icRouter\Interfaces\DefImpl\DefaultNodeBuilder;, (*3)
#### Create router ``` php $router = new Router(new DefaultNodeBuilder());
``` php $router->setRoutes([ new Route('simple', '/simple', array('module' => 'simple')), new Route('simple_param', '/param/:a', array('module' => 'simple_param', 'a' => 10), array('a' => '\d+')), // a is integer new Route('two_params', '/param/hello/:a/some/:b', array('module' => 'two_params', 'a' => 10, 'onemore' => 'time')), new Route('two_params_any', '/home/hello/:a/:b/', array('module' => 'two_params_any', 'a' => 10, 'b' => '10'), array('b' => '[01]+')), // b is string / number of 0' and 1' new Route('complex_param', '/complex/id_:id', array('module' => 'complex_param'), array('id' => '\d+')), new Route('home', '/', array('module' => 'home')), ]);, (*4)
#### Build route tree ``` php $router->build();
``` php $result = $router->match('/a/b/c/d/e');, (*5)
$result will be array of matching parameters (key value pairs) if route exists otherwise false is returned
#### Generate
``` php
$result = $router->generate('two_params', array('b' => 'aabb'));
First parameter is route name, second is parameters (key value pairs) array, (*6)
For production, because $router->build() is expensive you should cache already built router (APC, serializing, etc...), (*7)
Go to base dir and execute:, (*8)
phpunit test/RouterTest.php
perfomance banchmark beetween this library and some
regular expression routing library like one from symfony framework or similar., (*9)
Different approach for standard routing problem. Matching tree based.
MIT
route routing