chubbyphp/chubbyphp-psr7-middleware-singlepass-to-multipass-adapter

This package is abandoned and no longer maintained. No replacement package was suggested.

Chubbyphp Psr7 Middleware Adapter

1.0.2 2017-05-05 16:52 UTC

This package is not auto-updated.

Last update: 2020-09-22 18:51:25 UTC


README

Build Status Total Downloads Latest Stable Version Scrutinizer Code Quality Code Coverage

Description

This adapter can be used, if you dlike to use single pass (no response argument given) middleware within a multipass environment as for example slim or zend-expressive are.

Requirements

  • php: ~5.4
  • psr/http-message: ~1.0

Installation

Through Composer as chubbyphp/chubbyphp-psr7-middleware-singlepass-to-multipass-adapter.

composer require chubbyphp/chubbyphp-psr7-middleware-singlepass-to-multipass-adapter "~1.0"

Usage

The variable $next, within the single pass middleware arguments will always be a \Closure from the adapter.

<?php

use Chubbyphp\Psr7SinglePassToMultiPassAdapter\Psr7SinglePassToMultiPassAdapter;

$existingSinglePassMiddleware = function (RequestInterface $request, callable $next) {
    $request = $request->withHeader('X-Custom', '1');

    $response = $next($request);

    $body = $response->getBody();
    $body->seek(0, SEEK_END);
    $body->write('<!-- provided by x-custom -->');

    return $response;
};

$adapter = new Psr7SinglePassToMultiPassAdapter($existingSinglePassMiddleware);

$response = $adapter($request, $response, $next);

Copyright

Dominik Zogg 2016