handle($request) → emit($response)) with modern PSR-15 middleware (process($request, $response)). This aligns well with Laravel’s evolving middleware stack, particularly for applications migrating from older PSR-7-based frameworks (e.g., Slim, Silex) or integrating third-party middleware.Psr\Http\Message) and PSR-15 (Psr\Http\ServerMiddleware), which Laravel already supports. No additional dependencies are introduced beyond PHP’s standard libraries.$request->getBody()->rewind()) may need adjustments.fruitcake/laravel-psr7-middleware or similar.Tuupola\CallableHandler\Middleware\DoublePassMiddleware).CallableHandler trait for consistency.Illuminate\Http\Request/Response via PSR-7 adapters (e.g., symfony/http-foundation).use Tuupola\CallableHandler\Middleware\DoublePassMiddleware;
class LegacyMiddleware extends DoublePassMiddleware {
public function handle($request) { ... }
public function emit($response) { ... }
}
use Tuupola\CallableHandler\CallableHandler;
class Psr15Middleware implements Psr\Http\ServerMiddlewareInterface {
use CallableHandler;
public function process($request, $response) { ... }
}
composer.json to avoid surprises.try {
$handler->handle($request);
} catch (Throwable $e) {
report($e->withTraceToString());
}
app()->terminating to log middleware execution context.php artisan middleware:list).Symfony\Component\HttpFoundation\Response caching).$response after emit() may break PSR-15 expectations. Validate with:
$response = $middleware->process($request, $response);
assert($response->getStatusCode() === 200); // Example check
handle() after emit(). Test with:
$this->assertFalse($middleware instanceof RecursiveMiddleware);
UPGRADING.md.## PSR-7 to PSR-15 Migration Guide
1. Extend `DoublePassMiddleware` or use `CallableHandler` trait.
2. Replace `handle()` with `process($request, $response)`.
3. Move `emit()` logic into `process()`.
php artisan middleware:convert command to automate wrapping.How can I help you explore Laravel packages today?