dez-php/dez-router
最新稳定版本:v1.3.1
Composer 安装命令:
composer require dez-php/dez-router
包简介
Router Component
README 文档
README
Initialization
After composer install register few components to DI
$di = new Container(); $di->set( 'router', function() { return new Router(); } ); $di->set( 'eventDispatcher', function() { new Dispatcher(); } ); $di->set( 'request', function() { return new Request(); } ); // try to fetch router from container try { /** @var $router Router */ $router = $di->get( 'router' ); } catch ( \Exception $e ) { die($e->getMessage()); }
Register routes
$router->add( '/:controller' ); $router->add( '/:controller/:action' ); $router->add( '/:controller/:action/:id' ); $router->add( '/:controller/:action/:token' ); $router->add( '/:controller/:action.:format/:module-:do/:params/:statusCode' ) ->regex( 'format', 'html|json' ); // or import from files $router ->importFromArray( [ '/test.php' => [ 'matches' => [ 'controller' => 'test' ] ] ] ) ->importFromFileArray( './routes.php' ) ->importFromJson( './routes.json' ) ->importFromXml( './routes.xml' );
Sample files
routes.json
{ "/":{}, "/:format/:module/:controller/:action": { "regex": { "format": "html|json" } } }
routes.xml
<routes> <route match=":module"> <route match=":controller"> <route match=":action"> <route match=":hash" hash="[a-z0-9]{32}"></route> <route match=":params"></route> </route> </route> </route> <route match=":token" controller="auth" action="checkToken" token="[a-f0-9]{40}"></route> </routes>
routes.php
return [ '/dashboard' => [ 'matches' => [ 'module' => 'user-panel', 'controller' => 'index', 'action' => 'dashboard', ] ] ];
统计信息
- 总下载量: 294
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-09-27