phpdot/http-middleware 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

phpdot/http-middleware

Composer 安装命令:

composer require phpdot/http-middleware

包简介

PSR-15 middlewares for PHPdot

README 文档

README

PSR-15 middlewares for PHPdot

Install

composer require phpdot/http-middleware

Quick Start

Every middleware implements PSR-15 MiddlewareInterface and depends only on PSR interfaces, so it runs in any PSR-15 stack:

use PHPdot\HttpMiddleware\JsonBodyMiddleware;

// $responses and $streams are any PSR-17 factories (e.g. nyholm/psr7's Psr17Factory)
$middleware = new JsonBodyMiddleware($responses, $streams);

$response = $middleware->process($request, $handler);

Inside the phpdot framework

The middlewares are framework-agnostic — no phpdot/http dependency — so they slot into any PSR-15 pipeline. In a phpdot app, register one on the router:

$router->middleware(JsonBodyMiddleware::class);

The constructor's ResponseFactoryInterface and StreamFactoryInterface are resolved by the container (phpdot/http's ResponseFactory implements both).

Middlewares

JsonBodyMiddleware

Parses an application/json request body into the PSR-7 parsed body, so handlers read $request->getParsedBody() instead of hand-decoding. A malformed body is rejected with 400 — once, centrally — rather than surfacing as a misleading validation error downstream.

  • application/json is recognised (a charset suffix is fine); other content types pass through untouched.
  • An empty body or a top-level scalar is left unparsed, for the handler to treat as empty.
  • Malformed JSON → 400 {"error":"Malformed JSON request body."}, and the handler is not called.

PSR Standards

PSR Interface Usage
PSR-7 ServerRequestInterface Request the middleware reads and augments
PSR-7 ResponseInterface Return type
PSR-15 MiddlewareInterface The contract every middleware implements
PSR-15 RequestHandlerInterface The next handler in the pipeline
PSR-17 ResponseFactoryInterface Builds error responses (e.g. 400)
PSR-17 StreamFactoryInterface Builds response bodies

Development

composer test        # Run tests
composer analyse     # PHPStan level 10
composer cs-fix      # Fix code style
composer cs-check    # Check code style (dry run)
composer check       # Run all three

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固