I used the example https://stackoverflow.com/a/59681352/1650293 but it works perfectly in Actions, but I need it to happen in middleware. When I do the exact same thing in middleware, it returns error 500. What is missing? I couldn't understand why it didn't work.
This is my middware
namespace App\Application\Middleware;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface as RequestHandler;
use Slim\Psr7\Response;
use Slim\Routing\RouteContext;
use Slim\Interfaces\RouteCollectorInterface;
final class ACLMiddleware {
private $routeCollector;
    
    public function __construct(RouteCollectorInterface $routeCollector)
    {
        $this->routeCollector = $routeCollector;
    }
public function __invoke(Request $request, RequestHandler $handler): Response
    {
$routes = $this->routeCollector->getRoutes();
print_r($routes);
}
}
This is my container
    use Slim\Interfaces\RouteCollectorInterface;
    
    return [
    ...
    RouteCollectorInterface::class => function (ContainerInterface $container) {
            return $container->get(App::class)->getRouteCollector();
        },
...
];