tourze/psr15-chain-request-handler
Composer 安装命令:
composer require tourze/psr15-chain-request-handler
包简介
PSR-15 Chain Request Handler
README 文档
README
Introduction
A PSR-15 compatible chain request handler for PHP. This package allows you to combine multiple request handlers in a chain, processing HTTP requests sequentially until a handler returns a non-404 response. If all handlers return 404, a final 404 response is returned.
Features
- Chain multiple PSR-15 request handlers
- Automatically skips handlers that return 404
- Simple API for adding handlers dynamically
- Fully PSR-15 compatible
- Well-tested and easy to integrate
Installation
Requirements:
- PHP >= 8.1
- psr/http-message ^1.1|^2.0
- psr/http-server-handler ^1.0
- nyholm/psr7 ^1.8.2
Install via Composer:
composer require tourze/psr15-chain-request-handler
Quick Start
use Nyholm\Psr7\ServerRequest; use Nyholm\Psr7\Response; use Tourze\PSR15ChainRequestHandler\ChainRequestHandler; use Psr\Http\Server\RequestHandlerInterface; // Example handler that always returns 404 class NotFoundHandler implements RequestHandlerInterface { public function handle($request): Response { return new Response(404, body: 'Not Found'); } } // Example handler that returns 200 for a specific path class HelloHandler implements RequestHandlerInterface { public function handle($request): Response { if ($request->getUri()->getPath() === '/hello') { return new Response(200, body: 'Hello World'); } return new Response(404, body: 'Not Found'); } } $chain = new ChainRequestHandler([ new NotFoundHandler(), new HelloHandler(), ]); $request = new ServerRequest('GET', '/hello'); $response = $chain->handle($request); // $response->getStatusCode() === 200
Documentation
- API Reference
- See
tests/ChainRequestHandlerTest.phpfor usage scenarios
Advanced Usage
- Add handlers dynamically with
$chain->addHandler($handler); - Handlers are processed in the order they are added
- If no handler returns a non-404 response, the chain returns a 404 with body 'Not Found'
Contributing
- Please submit issues or pull requests via GitHub
- Follow PSR coding standards
- Run tests with PHPUnit before submitting PRs
License
MIT License. See LICENSE for details.
Changelog
See the CHANGELOG for release history and upgrade notes.
tourze/psr15-chain-request-handler 适用场景与选型建议
tourze/psr15-chain-request-handler 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 179 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 tourze/psr15-chain-request-handler 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tourze/psr15-chain-request-handler 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 179
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 25
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-24