bitshost / upmvc-psr-bridge
Optional PSR-7, PSR-15, and PSR-17 bridge pack for upMVC — run external PSR-15 middleware or PSR-7 handlers while keeping the upMVC kernel zero-dependency KISS.
v0.1.0
2026-11-28 20:59 UTC
Requires
- php: >=8.3
- bitshost/upmvc: ^2.8
- nyholm/psr7: ^1.8
- nyholm/psr7-server: ^1.1
- psr/http-message: ^2.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- phpstan/phpstan: ^2.2
- phpunit/phpunit: ^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Optional PSR-7, PSR-15, and PSR-17 bridge pack for any upMVC (^2.8) application — not SaaS-only.
Why a separate pack? The
upMVCkernel stays intentionally zero-dependency ("Direct PHP First"). Whenever a project needs PSR-7 (ServerRequestInterface/ResponseInterface), PSR-15 (MiddlewareInterface/RequestHandlerInterface, e.g.league/oauth2-server), or PSR-17 HTTP factories, install this lightweight opt-in bridge — zero kernel bloat for everyone else.
- PSR-7 + PSR-17 via
nyholm/psr7andnyholm/psr7-server(ServerRequestFactory::fromGlobals(),jsonResponse(),textResponse()). - PSR-15 Pipeline (
Psr15Pipeline) — compose external PSR-15 middleware in FIFO order with short-circuit support. - Native upMVC Adapter (
PsrMiddlewareAdapter) — wrap any external PSR-15 middleware around a regularupMVCcontroller action. - Clean SAPI Emitter (
ResponseEmitter) — emits status line, preserves multipleSet-Cookieheaders, and streams bodies safely.
Install
composer require bitshost/upmvc-psr-bridge
Usage
1. Run any external PSR-15 middleware around a native upMVC controller
use BitsHost\UpmvcPsr\PsrMiddlewareAdapter; use Psr\Http\Message\ServerRequestInterface; $out = PsrMiddlewareAdapter::run($externalPsr15Middleware, function (ServerRequestInterface $request) { $userId = $request->getAttribute('oauth_user_id'); // Continue with regular upMVC controller logic });
2. Compose a full PSR-15 pipeline and emit a PSR-7 response
use BitsHost\UpmvcPsr\Psr15Pipeline; use BitsHost\UpmvcPsr\ResponseEmitter; use BitsHost\UpmvcPsr\ServerRequestFactory; use Psr\Http\Message\ServerRequestInterface; $request = ServerRequestFactory::fromGlobals(); $pipeline = (new Psr15Pipeline())->withMiddleware($rateLimiterMw, $oauthMw); $response = $pipeline->handle($request, function (ServerRequestInterface $req) { return ServerRequestFactory::jsonResponse(['ok' => true, 'path' => $req->getUri()->getPath()]); }); ResponseEmitter::emit($response);
Local development
composer install
composer check # PHPStan level 5 + PHPUnit