💫 extension for zend-diactoros
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
sample
src/SfpDiactoros
tests/SfpDiactorosTest/Response
.gitignore
.travis.yml
README.md
composer.json
phpunit.xml.dist

README.md

sfp-diactoros-extension

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