Skip to content

Commit

Permalink
Merge pull request #689 from odan/middleware-response
Browse files Browse the repository at this point in the history
Fix Response instantiation in code example on middleware concepts page.
Closes #3309
  • Loading branch information
akrabat committed Jan 15, 2024
2 parents cd1dc81 + e7528e1 commit 8ef73ec
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions docs/v4/concepts/middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ This example middleware is a Closure.

```php
<?php
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface as RequestHandler;
use Slim\Factory\AppFactory;
use Psr\Http\Message\ResponseInterface as Response;

require __DIR__ . '/../vendor/autoload.php';

Expand All @@ -68,13 +68,13 @@ $app = AppFactory::create();
* @param Request $request PSR-7 request
* @param RequestHandler $handler PSR-15 request handler
*
* @return Response
* @return ResponseInterface
*/
$beforeMiddleware = function (Request $request, RequestHandler $handler) {
$beforeMiddleware = 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;
Expand Down Expand Up @@ -186,20 +186,24 @@ Application middleware is invoked for every **incoming** HTTP request. Add appli

```php
<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface as RequestHandler;
use Slim\Factory\AppFactory;
<<<<<<< HEAD
use Psr\Http\Message\ResponseInterface as Response;
=======
>>>>>>> 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;
Expand Down

0 comments on commit 8ef73ec

Please sign in to comment.