首页 > PHP资讯 > PHP培训技术 > PHP 路由器 Pux

PHP 路由器 Pux

PHP培训技术

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 PuxPatternCompiler class.use PuxExecutor;class ProductController {    public function listAction() {        return 'product list';    }    public function itemAction($id) {         return "product $id";    }}$mux = new PuxMux;$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);
本文由欣才IT学院整理发布,未经许可,禁止转载。