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

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages