zendframework/zend-diactoros
zendframework/zend-diactoros provides PSR-7 HTTP message implementations for PHP, including ServerRequest, Response, Stream, UploadedFile and Uri. Useful for building middleware, APIs and frameworks with interoperable request/response handling.
zend-diactoros is a PSR-7 implementation for HTTP messages (requests, responses, streams, etc.). Though archived and unmaintained, it’s still used in legacy Zend Framework/Laminas projects. Start by installing it via Composer:
composer require zendframework/zend-diactoros
Your first use case will likely be building or parsing HTTP messages—for example, constructing a response in a lightweight framework or middleware stack:
use Zend\Diactoros\Response;
use Zend\Diactoros\StatusCode;
$response = (new Response())
->withStatus(StatusCode::STATUS_OK)
->withHeader('Content-Type', 'text/plain')
->getBody()->write('Hello, PSR-7!');
ServerRequest and Response to integrate with PSR-15-style middleware (e.g., Expressive/Laminas Mezzio).ServerRequestFactory::fromGlobals() to convert $_SERVER, $_GET, $_POST, etc., into a typed ServerRequestInterface.php://input manually with Zend\Diactoros\Stream for testability or in-memory streams:
$stream = new Stream('php://temp', 'r+');
$stream->write(json_encode(['status' => 'ok']));
$response = new Response($stream, 200, ['Content-Type' => 'application/json']);
ResponseInterface and ServerRequestInterface from this package feed directly into routing and dispatching layers.laminas/laminas-diactoros (the official fork) instead. The zendframework/ namespace is unmaintained and not compatible with modern PSR-7/17 extensions.with*() methods:
$response = $response->withHeader('X-Debug', 'true'); // OK
$response->withHeader(...); // Broken: original untouched
Stream instance across requests/responses can cause “stream already consumed” errors—always clone or create fresh streams in tests or pipelines.Response or ServerRequest to add domain-specific helpers (e.g., withJsonError()), but avoid overriding __toString()—PSR-7 messages aren’t meant to be rendered.var_dump($request->getUri()) or json_encode((array) $request) for quick inspection—but prefer unit tests over var_dump in production.How can I help you explore Laravel packages today?