Symfony\Bundle\FrameworkBundle\Controller\Controller::stream PHP Method

stream() protected method

Streams a view.
protected stream ( string $view, array $parameters = [], Symfony\Component\HttpFoundation\StreamedResponse $response = null ) : Symfony\Component\HttpFoundation\StreamedResponse
$view string The view name
$parameters array An array of parameters to pass to the view
$response Symfony\Component\HttpFoundation\StreamedResponse A response instance
return Symfony\Component\HttpFoundation\StreamedResponse A StreamedResponse instance
    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;
    }

Usage Example

 public function testStreamTemplating()
 {
     $templating = $this->getMock('Symfony\\Component\\Routing\\RouterInterface');
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $container->expects($this->at(0))->method('has')->willReturn(true);
     $container->expects($this->at(1))->method('get')->will($this->returnValue($templating));
     $controller = new Controller();
     $controller->setContainer($container);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\StreamedResponse', $controller->stream('foo'));
 }
All Usage Examples Of Symfony\Bundle\FrameworkBundle\Controller\Controller::stream