Skip to content

Commit f2d96d5

Browse files
committed
Revert "don't use BufferedOutput on Symfony 2.3"
This reverts commit 4e9e0dd.
1 parent ae8474d commit f2d96d5

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

Diff for: cookbook/console/command_in_controller.rst

+11-12
Original file line numberDiff line numberDiff line change
@@ -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\StreamOutput;
33+
use Symfony\Component\Console\Output\BufferedOutput;
3434
use Symfony\Component\HttpFoundation\Response;
3535

3636
class SpoolController extends Controller
@@ -46,14 +46,12 @@ 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 StreamOutput(tmpfile(), StreamOutput::VERBOSITY_NORMAL);
49+
$output = new BufferedOutput();
5050
$application->run($input, $output);
5151

5252
// 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+
5755
// return new Response(""), if you used NullOutput()
5856
return new Response($content);
5957
}
@@ -62,7 +60,7 @@ Run this command from inside your controller via::
6260
Showing Colorized Command Output
6361
--------------------------------
6462

65-
By telling the ``StreamOutput`` it is decorated via the third parameter,
63+
By telling the ``BufferedOutput`` it is decorated via the second parameter,
6664
it will return the Ansi color-coded content. The `SensioLabs AnsiToHtml converter`_
6765
can be used to convert this to colorful HTML.
6866

@@ -78,8 +76,8 @@ Now, use it in your controller::
7876
namespace AppBundle\Controller;
7977

8078
use SensioLabs\AnsiConverter\AnsiToHtmlConverter;
79+
use Symfony\Component\Console\Output\BufferedOutput;
8180
use Symfony\Component\Console\Output\OutputInterface;
82-
use Symfony\Component\Console\Output\StreamOutput;
8381
use Symfony\Component\HttpFoundation\Response;
8482
// ...
8583

@@ -88,14 +86,15 @@ Now, use it in your controller::
8886
public function sendSpoolAction($messages = 10)
8987
{
9088
// ...
91-
$output = new StreamOutput(tmpfile(), StreamOutput::VERBOSITY_NORMAL, true);
89+
$output = new BufferedOutput(
90+
OutputInterface::VERBOSITY_NORMAL,
91+
true // true for decorated
92+
);
9293
// ...
9394

9495
// return the output
9596
$converter = new AnsiToHtmlConverter();
96-
rewind($output->getStream());
97-
$content = stream_get_contents($output->getStream());
98-
fclose($output->getStream());
97+
$content = $output->fetch();
9998

10099
return new Response($converter->convert($content));
101100
}

0 commit comments

Comments
 (0)