Skip to content

Handle Symfony StreamedResponse #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions Bridges/HttpKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Stack\Builder;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
use Symfony\Component\HttpFoundation\StreamedResponse as SymfonyStreamedResponse;

class HttpKernel implements BridgeInterface
{
Expand All @@ -36,10 +37,10 @@ class HttpKernel implements BridgeInterface
*/
public function bootstrap($appBootstrap, $appenv)
{
// include applications autoload
// include applications autoload
$autoloader = dirname(realpath($_SERVER['SCRIPT_NAME'])) . '/vendor/autoload.php';
if (file_exists($autoloader)) {
require_once $autoloader;
require_once $autoloader;
}

if (false === class_exists($appBootstrap)) {
Expand Down Expand Up @@ -145,6 +146,18 @@ protected static function mapResponse(ReactResponse $reactResponse,
{
$headers = $syResponse->headers->all();
$reactResponse->writeHead($syResponse->getStatusCode(), $headers);
$reactResponse->end($syResponse->getContent());

// @TODO convert StreamedResponse in an async manner
if ($syResponse instanceof SymfonyStreamedResponse) {
ob_start();
$syResponse->sendContent();
$content = ob_get_contents();
ob_end_clean();
}
else {
$content = $syResponse->getContent();
}

$reactResponse->end($content);
}
}