borschphp/router
Composer 安装命令:
composer require borschphp/router
包简介
A FastRoute router implementation.
README 文档
README
Borsch Router
An awesome router implementation with support for multiple routing engines, including `nikic/fast-route`.
Table of Contents
About The Project
A collection of router implementations, inspired by the one you can find in the excellent Mezzio Routing Interfaces. Among them :
- a router is based on nikic/fast-route
- a router is based on a tree structure
- a router is based on a simple comparator
You need to provide a PSR-7 ServerRequestInterface in order to match the routes.
A PSR-7 ResponseInterface must be returned by the route handler.
Getting Started
Prerequisites
You need PHP >= 8.2 to use Borsch\Router but the latest stable version of PHP is always recommended.
It also requires an implementation of PSR-7 HTTP Message.
The Laminas Diactoros Project is used for testing, and in the examples below.
Installation
Via composer :
composer require borschphp/router
Usage
require_once __DIR__.'/vendor/autoload.php'; $router = new \Borsch\Router\FastRouteRouter(); $router->addRoute(new \Borsch\Router\Route( ['GET'], '/articles/{id:\d+}[/{slug}]', new ArticleHandler(), // Instance of RequestHandlerInterface 'articles.id.title' )); $server_request = \Laminas\Diactoros\ServerRequestFactory::fromGlobals(); // $route_result is an instance of RouteResultInterface $route_result = $router->match($server_request); // $route is an instance of RouteInterface (or false if no match) $route = $route_result->getMatchedRoute(); if (!$route) { return new \Laminas\Diactoros\Response('Not Found', 404); } // $response is an instance of ResponseInterface $response = $route->getHandler()->handle($server_request); // Send the response back to the client or other...
Available routers
| Router Name | Description | Cache | Speed | Speed with cache | Variables | Optional Parts |
|---|---|---|---|---|---|---|
FastRouteRouter |
A nikic/fast-route based router |
✅ | Medium | Fast | ✅ | ✅ |
TreeRouter |
A tree based router | ✅ | Fast | Very fast | ✅ | ❌ |
SimpleConditionalRouter |
A very simple comparator based router | ❌ | Very fast | ❌ | ❌ | ❌ |
Testing
This package uses Pest as test framework.
To run tests :
./vendor/bin/pest tests
Mutation testing has also been added to this package:
XDEBUG_MODE=coverage ./vendor/bin/pest --mutate --parallel
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
Distributed under the MIT License. See License File for more information.
Acknowledgments
A big thanks to these projects for inspiration or because they're used in this one:
borschphp/router 适用场景与选型建议
borschphp/router 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.35k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 05 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 borschphp/router 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 borschphp/router 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.35k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 3
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-05-27