pushinbr/pam-http-psr
pushinbr/pam-http-psr provides PSR-7, PSR-15, and PSR-17 interoperability using the official PHP-FIG interfaces.
Start here
Section titled “Start here”Install and verify the PAM runtime first, create an HTTP application, and add the PSR bridge through PAM’s Composer passthrough:
curl -fsSL https://github.com/push-in/pam/releases/latest/download/install.sh | shpam doctorpam init my-api --template httpcd my-apipam composer require pushinbr/pam-http-psrUse a PSR-15 handler
Section titled “Use a PSR-15 handler”Pass a PSR-15 handler to the application:
use Pam\App;use Psr\Http\Message\ResponseInterface;use Psr\Http\Message\ServerRequestInterface;use Psr\Http\Server\RequestHandlerInterface;
final class HealthHandler implements RequestHandlerInterface{ public function handle(ServerRequestInterface $request): ResponseInterface { $factory = new Pam\Http\Psr7\Factory(); $response = $factory->createResponse(200); $response->getBody()->write('healthy');
return $response; }}
$app = new App();$app->handler(new HealthHandler());$app->listen(3000);When a PSR handler is configured, PAM registers it at the runtime boundary and converts the native request and response.
Add PSR-15 middleware
Section titled “Add PSR-15 middleware”$app->middleware(new RequestIdMiddleware());$app->middleware(new AuthenticationMiddleware());Objects implementing Psr\Http\Server\MiddlewareInterface enter the PSR middleware chain. PAM-native middleware continues to use the PAM request, response, and handler contracts.
Implemented PSR-7 surface
Section titled “Implemented PSR-7 surface”The package includes implementations for:
- streams;
- URIs;
- requests and server requests;
- responses;
- uploaded files; and
- PSR-17 factories.
Messages follow PSR immutability: with*() methods return cloned values.
Boundary and limitations
Section titled “Boundary and limitations”The bridge makes standards-based handlers interoperable. It does not make a synchronous PSR middleware asynchronous, and it does not guarantee that middleware written for FPM is free of long-lived global state.
Check:
- stream ownership and closing behavior;
- uploaded-file lifetime;
- middleware statics and singletons;
- body size and buffering assumptions;
- SAPI checks; and
- exception and cancellation cleanup.
Use the native PAM transport suite for protocol, timeout, disconnect, and streaming behavior. Unit tests that call a PSR handler directly do not cover that boundary.
Concrete implementations
Section titled “Concrete implementations”The Pam\Http\Psr7 namespace provides the complete PSR implementation set:
| Type | Interfaces/role |
|---|---|
Stream |
StreamInterface; string or resource-backed body |
Uri |
UriInterface; immutable URI components and normalization |
Message |
Shared abstract immutable headers, protocol and body behavior |
Request |
RequestInterface |
ServerRequest |
ServerRequestInterface; server, cookie, query, upload, parsed-body and attribute state |
Response |
ResponseInterface |
UploadedFile |
UploadedFileInterface |
Factory |
Request, response, server-request, stream, uploaded-file and URI PSR-17 factories |
Pipeline |
RequestHandlerInterface; executes PSR-15 middleware before the destination handler |
These classes are declared only when the official PHP-FIG message interfaces
are installed. Prefer the interfaces in application signatures. Streams may be
detached or closed; immutable with*() operations clone messages rather than
mutating the original.