PSR-7
HTTP messages, streams, URIs and multipart for PHP.
Installation
Section titled “Installation”composer config repositories.localzet-psr-7 vcs https://github.com/localzet/PSR-7composer require localzet/psr7:dev-mainHTTP messages and streams
Section titled “HTTP messages and streams”Types live under localzet\PSR7: Request/Response/ServerRequest, streams, Uri/UriResolver and MultipartStream. This is a separate message model; do not confuse it with Server 7’s mutable localzet\Server\Protocols\Http\Response. ServerRequest accepts a raw HTTP buffer; fromGlobals() targets PHP globals.
Check stream seekability/readability/writability, cursor position and resource ownership. For proxies/redirects, normalize URIs and validate destinations after resolving relative references. The manifest requires Server 4.x. Dedicated conformance tests remain necessary for immutable with-methods, URI encoding, multipart and interoperability; installation does not prove PSR-7 compliance.
Requirements
Section titled “Requirements”- php: ^8.2
- localzet/server: ^4.1
- psr/http-message: ^2.0
Example
Section titled “Example”<?php
declare(strict_types=1);
use localzet\PSR7\Request;use localzet\PSR7\Response;use localzet\PSR7\Stream;
require __DIR__ . '/vendor/autoload.php';
$request = new Request('get', 'https://example.test/items?page=2');$response = new Response(200, ['Content-Type' => 'application/json'], '{"ok":true}');$tagged = $response->withHeader('X-Mode', 'preview');$accepted = $response->withStatus(202);
$resource = fopen('php://temp', 'r+');fwrite($resource, 'abcdef');rewind($resource);$stream = new Stream($resource);try { echo json_encode([ 'method' => $request->getMethod(), 'target' => $request->getRequestTarget(), 'same_header_object' => $tagged === $response, 'original_status' => $response->getStatusCode(), 'new_status' => $accepted->getStatusCode(), 'first_bytes' => $stream->read(2), 'remaining_bytes' => $stream->getContents(), ], JSON_THROW_ON_ERROR), PHP_EOL;} finally { $stream->close();}Source · AGPL-3.0