I am trying to use the ValidationErrorsMiddleware.php class as middleware, so I added the following code to my bootstrap / app.php:
$app->add(new App\Middleware\ValidationErrorsMiddleware($container));
I got the following errors after the above code was added to my app.php:
Fatal error: Uncaught exception 'RuntimeException' with message 'Unexpected data in output buffer. Maybe you have characters before an opening <?php tag?' in C:\wamp64\www\authentication\vendor\slim\slim\Slim\App.php on line 552 RuntimeException: Unexpected data in output buffer. Maybe you have characters before an opening <?php tag? in C:\wamp64\www\authentication\vendor\slim\slim\Slim\App.php on line 552
Just in case, someone needs to look at the code of my classes and app.php, I included them here
ValidationErrorsMiddleware.php
<?php namespace App\Middleware; class ValidationErrorsMiddleware extends Middleware { public function __invoke($request, $response, $next) { var_dump('middleware'); $response = $next($request, $response); return $response; } }
Middleware.php
<?php namespace App\Middleware; class Middleware { protected $container; public function __construct($container) { $this->container = $container; } }
app.php
<?php session_start(); require __DIR__ . '/../vendor/autoload.php'; $app = new \Slim\App([ 'settings' => [ 'determineRouteBeforeAppMiddleware' => false, 'displayErrorDetails' => true, 'db' => [ // Eloquent configuration 'driver' => 'mysql', 'host' => 'localhost', 'database' => 'phpdb', 'username' => 'root', 'password' => 'root', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', ] ], ]); $container = $app->getContainer(); $app->add(new App\Middleware\ValidationErrorsMiddleware($container)); require __DIR__ . '/../app/routes.php';