From e7528e1ac584c139b3cf0dd945cd26a05c4f371e Mon Sep 17 00:00:00 2001 From: Daniel Opitz Date: Sun, 14 Jan 2024 12:43:17 +0100 Subject: [PATCH] Fix Response instantiation --- docs/v4/concepts/middleware.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/v4/concepts/middleware.md b/docs/v4/concepts/middleware.md index 77718dde..e03a3d3f 100644 --- a/docs/v4/concepts/middleware.md +++ b/docs/v4/concepts/middleware.md @@ -53,10 +53,10 @@ This example middleware is a Closure. ```php handle($request); $existingContent = (string) $response->getBody(); - $response = new Response(); + $response = $app->getResponseFactory()->createResponse(); $response->getBody()->write('BEFORE' . $existingContent); return $response; @@ -186,20 +186,24 @@ Application middleware is invoked for every **incoming** HTTP request. Add appli ```php >>>>>> c9ce721 (Fix Response instantiation) require __DIR__ . '/../vendor/autoload.php'; $app = AppFactory::create(); -$app->add(function (Request $request, RequestHandler $handler) { +$app->add(function (Request $request, RequestHandler $handler) use ($app) { $response = $handler->handle($request); $existingContent = (string) $response->getBody(); - $response = new Response(); + $response = $app->getResponseFactory()->createResponse(); $response->getBody()->write('BEFORE ' . $existingContent); return $response;