phpdot / http-middleware
PSR-15 middlewares for PHPdot.
Requires
- php: >=8.5
- psr/http-factory: ^1.0
- psr/http-message: ^2.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.94
- phpdot/http: ^0.1
- phpstan/phpstan: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^13.0
README
PSR-15 middlewares for PHPdot. Each is a small, framework-agnostic middleware that plugs into any
PSR-15 pipeline. Currently: JsonBodyMiddleware, which decodes JSON request bodies into the request's
parsed body.
Table of Contents
Requirements
| Requirement | Constraint |
|---|---|
| PHP | >= 8.5 |
psr/http-factory |
^1.0 |
psr/http-message |
^2.0 |
psr/http-server-handler |
^1.0 |
psr/http-server-middleware |
^1.0 |
Bring any PSR-7/PSR-17 implementation (for example phpdot/http).
Installation
composer require phpdot/http-middleware
Usage
JsonBodyMiddleware
For requests with a application/json content type, it decodes the body and exposes it via
getParsedBody(); a malformed body returns a 400 with a JSON error, and non-JSON or empty bodies pass
straight through. Construct it with your PSR-17 response and stream factories and add it to the pipeline:
use PHPdot\HttpMiddleware\JsonBodyMiddleware; $middleware = new JsonBodyMiddleware($responseFactory, $streamFactory); // In your PSR-15 pipeline, before handlers that read getParsedBody() $app->pipe($middleware);
// Downstream, the decoded body is available as the parsed body: $data = $request->getParsedBody();
Testing
composer install composer test # PHPUnit composer analyse # PHPStan, level max + strict rules composer cs-check # PHP-CS-Fixer composer check # All three
License
MIT.
This repository is a read-only mirror, generated by CI from phpdot/monorepo. Pull requests and issues belong in the monorepo.