struggle-for-php/sfp-diactoros-extension

An extension for zend-diactoros.

0.1.0 2015-06-05 15:58 UTC

This package is auto-updated.

Last update: 2024-04-06 14:36:17 UTC


README

Build Status

A extension for zend-diactoros.

Feature

SfpDiactoros\Response\SwitchingEmitter allows fpassthru() with FpassthruInterface.

just changed only in emitBody() from original Zend\Diactoros\Response\SapiEmitter.

// SapiEmitter
echo $response->getBody();
// SwitchingEmitter
if ($body instanceof FpassthruInterface) {
    $resource = $body->detach();
    if ($body instanceof RewindFpassthruInterface) {
        rewind($resource);
    }
    fpassthru($resource);
} else {
    echo $response->getBody();
}

Usage

use SfpDiactoros\Response\SwitchingEmitter;

$server = Server::createServer($app, $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
$server->setEmitter(new SwitchingEmitter);
use SfpDiactoros\Stream\RewindFpassthruStream;

$fp = fopen('/tmp/bigsize', 'r');
$response->withBody(new RewindFpassthruStream($fp));