定制 borschphp/router 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

borschphp/router

Composer 安装命令:

composer require borschphp/router

包简介

A FastRoute router implementation.

README 文档

README

PHP Composer Latest Stable Version License

Borsch Router

An awesome router implementation with support for multiple routing engines, including `nikic/fast-route`.


Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Testing
  5. Contributing
  6. License
  7. Acknowledgments

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.

(back to top)

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

(back to top)

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

(back to top)

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

(back to top)

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!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See License File for more information.

(back to top)

Acknowledgments

A big thanks to these projects for inspiration or because they're used in this one:

(back to top)

borschphp/router 适用场景与选型建议

borschphp/router 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.35k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 05 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 borschphp/router 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 borschphp/router 我们能提供哪些服务?
定制开发 / 二次开发

基于 borschphp/router 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.35k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 3
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-05-27