Pux 介绍
Pux 是一个超级高性能的 PHP 路由器,是对 PHP Router 的重新设计。测试速度比 symfony 快 48.5 倍,比正则表达式方式路由快
31 倍。
路由匹配示例:
/post /post/:id => matches /post/33 /post/:id(/:title) => matches /post/33, /post/33/post%20title /post/:id(\.:format) => matches /post/33, /post/33.json .. /post/33.xml
示例代码:
require 'vendor/autoload.php'; // use PCRE patterns you need Pux\PatternCompiler class. use Pux\Executor; class ProductController { public function listAction() { return 'product list'; } public function itemAction($id) { return "product $id"; } } $mux = new Pux\Mux; $mux->add('/product', ['ProductController','listAction']); $mux->add('/product/:id', ['ProductController','itemAction'] , [ 'require' => [ 'id' => '\d+', ], 'default' => [ 'id' => '1', ] ]); $route = $mux->dispatch('/product/1'); Executor::execute($route);
Pux 官网
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。