protected function stream($view, array $parameters = array(), StreamedResponse $response = null)
{
if ($this->container->has('templating')) {
$templating = $this->container->get('templating');
$callback = function () use($templating, $view, $parameters) {
$templating->stream($view, $parameters);
};
} elseif ($this->container->has('twig')) {
$twig = $this->container->get('twig');
$callback = function () use($twig, $view, $parameters) {
$twig->display($view, $parameters);
};
} else {
throw new \LogicException('You can not use the "stream" method if the Templating Component or the Twig Bundle are not available.');
}
if (null === $response) {
return new StreamedResponse($callback);
}
$response->setCallback($callback);
return $response;
}