@@ -30,7 +30,7 @@ Run this command from inside your controller via::
3030 use Symfony\Bundle\FrameworkBundle\Console\Application;
3131 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
3232 use Symfony\Component\Console\Input\ArrayInput;
33- use Symfony\Component\Console\Output\BufferedOutput ;
33+ use Symfony\Component\Console\Output\StreamOutput ;
3434 use Symfony\Component\HttpFoundation\Response;
3535
3636 class SpoolController extends Controller
@@ -46,12 +46,14 @@ Run this command from inside your controller via::
4646 '--message-limit' => $messages,
4747 ));
4848 // You can use NullOutput() if you don't need the output
49- $output = new BufferedOutput( );
49+ $output = new StreamOutput(tmpfile(), StreamOutput::VERBOSITY_NORMAL );
5050 $application->run($input, $output);
5151
5252 // return the output, don't use if you used NullOutput()
53- $content = $output->fetch();
54-
53+ rewind($output->getStream());
54+ $content = stream_get_contents($output->getStream());
55+ fclose($output->getStream());
56+
5557 // return new Response(""), if you used NullOutput()
5658 return new Response($content);
5759 }
@@ -60,7 +62,7 @@ Run this command from inside your controller via::
6062Showing Colorized Command Output
6163--------------------------------
6264
63- By telling the ``BufferedOutput `` it is decorated via the second parameter,
65+ By telling the ``StreamOutput `` it is decorated via the third parameter,
6466it will return the Ansi color-coded content. The `SensioLabs AnsiToHtml converter `_
6567can be used to convert this to colorful HTML.
6668
@@ -76,8 +78,8 @@ Now, use it in your controller::
7678 namespace AppBundle\Controller;
7779
7880 use SensioLabs\AnsiConverter\AnsiToHtmlConverter;
79- use Symfony\Component\Console\Output\BufferedOutput;
8081 use Symfony\Component\Console\Output\OutputInterface;
82+ use Symfony\Component\Console\Output\StreamOutput;
8183 use Symfony\Component\HttpFoundation\Response;
8284 // ...
8385
@@ -86,15 +88,14 @@ Now, use it in your controller::
8688 public function sendSpoolAction($messages = 10)
8789 {
8890 // ...
89- $output = new BufferedOutput(
90- OutputInterface::VERBOSITY_NORMAL,
91- true // true for decorated
92- );
91+ $output = new StreamOutput(tmpfile(), StreamOutput::VERBOSITY_NORMAL, true);
9392 // ...
9493
9594 // return the output
9695 $converter = new AnsiToHtmlConverter();
97- $content = $output->fetch();
96+ rewind($output->getStream());
97+ $content = stream_get_contents($output->getStream());
98+ fclose($output->getStream());
9899
99100 return new Response($converter->convert($content));
100101 }
0 commit comments