Output Buffering Middleware

The Output Buffering Middleware enables you to switch between two modes of output buffering: APPEND (default) and PREPEND mode. The APPEND mode will use the existing response body to append the contents.The PREPEND mode will create a new response body object and prepend the contents to the output from the existing response body.This middleware should be placed on the center of the middleware stack so it gets executed last.

Usage

  1. <?php
  2. use Slim\Factory\AppFactory;
  3. use Slim\Middleware\OutputBufferingMiddleware;
  4. use Slim\Psr7\Factory\StreamFactory;
  5. require __DIR__ . '/../vendor/autoload.php';
  6. $app = AppFactory::create();
  7. $streamFactory = new StreamFactory();
  8. /**
  9. * The two modes available are
  10. * OutputBufferingMiddleware::APPEND (default mode) - Appends to existing response body
  11. * OutputBufferingMiddleware::PREPEND - Creates entirely new response body
  12. */
  13. $mode = OutputBufferingMiddleware::APPEND;
  14. $outputBufferingMiddleware = new OutputBufferingMiddleware($streamFactory, $mode);
  15. $app->add($outputBufferingMiddleware);
  16. // ...
  17. $app->run();