Skip to content

struggle-for-php/sfp-diactoros-extension

Repository files navigation

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

About

💫 extension for zend-diactoros

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages