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