Search by

bitshost / upmvc-psr-bridge

bitshost

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.

Package info

github.com/upMVC/upMVC-PSR-Bridge

Homepage

pkg:composer/bitshost/upmvc-psr-bridge

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.0 2026-11-28 20:59 UTC

This package is auto-updated.

Last update: 2026-11-28 21:15:17 UTC


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 upMVC kernel 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/psr7 and nyholm/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 regular upMVC controller action.
  • Clean SAPI Emitter (ResponseEmitter) — emits status line, preserves multiple Set-Cookie headers, 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