felipecwb / routing
PHP的一个更简单的路由器。
v0.4
2014-12-19 01:18 UTC
Requires
- php: >=5.4
- symfony/http-foundation: 2.5.*@stable
Requires (Dev)
- phpmd/phpmd: *
- phpunit/phpunit: 4.2.*
- squizlabs/php_codesniffer: *
This package is not auto-updated.
Last update: 2024-09-24 02:39:11 UTC
README
一个更简单的PHP路由库。
你需要了解正则表达式模式。
安装
{ "felipecwb/routing": "dev-master" }
示例:
<?php use Felipecwb\Routing\Router; // Exceptions use Felipecwb\Routing\Exception\ResolverException; use Felipecwb\Routing\Exception\RouteNotFoundException; $router = Router::create(); $router->add('/', function () { echo "Hello World!"; }); $router->add('/hello/(\w+)', function ($name) { echo "Hello {$name}!"; }); $router->add('/article/(\d+)', function ($id, $extraStr) { echo "Article {$id}! ${extraStr}"; }); try { $router->dispatch('/'); // with arguments $router->dispatch('/hello/felipecwb'); // with extra arguments $router->dispatch('/hello/10', ['Extra String!']); } catch (RouteNotFoundException $e) { echo "Sorry! The target can not be found!"; } catch (ResolverException $e) { echo "Sorry! The target can not be executed!"; } die;
贡献
请随时贡献。
- 创建一个问题。
- 遵循PSR-2和PSR-4
- 使用PHPUnit进行测试
许可证MIT