Minimal middleware runner

dev-master 2016-02-14 14:07 UTC

This package is auto-updated.

Last update: 2020-10-05 10:26:33 UTC


Build Status

MidRun is a minimal PHP middleware runner, and transports PSR-7 HTTP message interfaces.

class RenanBr\MidRun
    public function __construct(array|Transversable $middlewares);

    public function __invoke(
        Psr\Http\Message\RequestInterface $request,
        Psr\Http\Message\ResponseInterface $response,
        callable $next = null
    ): Psr\Http\Message\ResponseInterface;

It's useful to...

  • build simple and fancy websites
  • group middlewares in order to simplify your application
  • run integration tests among middlewares
  • kill time on the rainy days

MidRun is not a framework, router, stack of middleware, configuration manager, potato, ...


composer require renanbr/midrun


MidRun accepts array or Transversable as stack of middlewares.

$middlewares = [
    function ($request, $response, $next) {
        $response->getBody()->write('Hello world!');
        return $next($request, $response);
    function ($request, $response, $next) {
        echo $response->getBody();
        return $next($request, $response);

$runner = new RenenBr\MidRun($middlewares);
$response = $runner(new Zend\Diactoros\Request, new Zend\Diactoros\Response);

This sample uses zendframework/zend-diactoros as PSR-7 implementation.