Skip to content

pushinbr/pam-http-psr

pushinbr/pam-http-psr provides PSR-7, PSR-15, and PSR-17 interoperability using the official PHP-FIG interfaces.

Install and verify the PAM runtime first, create an HTTP application, and add the PSR bridge through PAM’s Composer passthrough:

Terminal window
curl -fsSL https://github.com/push-in/pam/releases/latest/download/install.sh | sh
pam doctor
pam init my-api --template http
cd my-api
pam composer require pushinbr/pam-http-psr

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.

$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.

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.

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.

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.