Skip to content
This repository has been archived by the owner on Apr 21, 2018. It is now read-only.

This adapter can be used, if you dlike to use single pass (no response argument given) middleware within a multipass environment

License

Notifications You must be signed in to change notification settings

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

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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

About

This adapter can be used, if you dlike to use single pass (no response argument given) middleware within a multipass environment

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages