@@ -30,7 +30,7 @@ Run this command from inside your controller via::
30
30
use Symfony\Bundle\FrameworkBundle\Console\Application;
31
31
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
32
32
use Symfony\Component\Console\Input\ArrayInput;
33
- use Symfony\Component\Console\Output\BufferedOutput ;
33
+ use Symfony\Component\Console\Output\StreamOutput ;
34
34
use Symfony\Component\HttpFoundation\Response;
35
35
36
36
class SpoolController extends Controller
@@ -46,12 +46,14 @@ Run this command from inside your controller via::
46
46
'--message-limit' => $messages,
47
47
));
48
48
// You can use NullOutput() if you don't need the output
49
- $output = new BufferedOutput( );
49
+ $output = new StreamOutput(tmpfile(), StreamOutput::VERBOSITY_NORMAL );
50
50
$application->run($input, $output);
51
51
52
52
// 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
+
55
57
// return new Response(""), if you used NullOutput()
56
58
return new Response($content);
57
59
}
@@ -60,7 +62,7 @@ Run this command from inside your controller via::
60
62
Showing Colorized Command Output
61
63
--------------------------------
62
64
63
- By telling the ``BufferedOutput `` it is decorated via the second parameter,
65
+ By telling the ``StreamOutput `` it is decorated via the third parameter,
64
66
it will return the Ansi color-coded content. The `SensioLabs AnsiToHtml converter `_
65
67
can be used to convert this to colorful HTML.
66
68
@@ -76,8 +78,8 @@ Now, use it in your controller::
76
78
namespace AppBundle\Controller;
77
79
78
80
use SensioLabs\AnsiConverter\AnsiToHtmlConverter;
79
- use Symfony\Component\Console\Output\BufferedOutput;
80
81
use Symfony\Component\Console\Output\OutputInterface;
82
+ use Symfony\Component\Console\Output\StreamOutput;
81
83
use Symfony\Component\HttpFoundation\Response;
82
84
// ...
83
85
@@ -86,15 +88,14 @@ Now, use it in your controller::
86
88
public function sendSpoolAction($messages = 10)
87
89
{
88
90
// ...
89
- $output = new BufferedOutput(
90
- OutputInterface::VERBOSITY_NORMAL,
91
- true // true for decorated
92
- );
91
+ $output = new StreamOutput(tmpfile(), StreamOutput::VERBOSITY_NORMAL, true);
93
92
// ...
94
93
95
94
// return the output
96
95
$converter = new AnsiToHtmlConverter();
97
- $content = $output->fetch();
96
+ rewind($output->getStream());
97
+ $content = stream_get_contents($output->getStream());
98
+ fclose($output->getStream());
98
99
99
100
return new Response($converter->convert($content));
100
101
}
0 commit comments