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

此包已被废弃,不再维护。未建议替代包。

Chubbyphp Psr7 中间件适配器

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

描述

如果希望在多阶段环境中使用单阶段(未提供响应参数)中间件,例如在slimzend-expressive中,则可以使用此适配器。

要求

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

安装

通过Composer安装,包名为chubbyphp/chubbyphp-psr7-middleware-singlepass-to-multipass-adapter

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

用法

在单阶段中间件的参数中,变量$next始终是来自适配器的\Closure。

<?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);

版权

Dominik Zogg 2016