Skip to content

Commit

Permalink
Add Buffered Console Output (#36404)
Browse files Browse the repository at this point in the history
* add buffered console output

* Apply fixes from StyleCI (#36403)

* change visibility
  • Loading branch information
taylorotwell authored Feb 26, 2021
1 parent 50b4a94 commit 8a14453
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/Illuminate/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\PhpExecutableFinder;

Expand Down Expand Up @@ -86,7 +85,7 @@ public function run(InputInterface $input = null, OutputInterface $output = null

$this->events->dispatch(
new CommandStarting(
$commandName, $input, $output = $output ?: new ConsoleOutput
$commandName, $input, $output = $output ?: new BufferedConsoleOutput
)
);

Expand Down
41 changes: 41 additions & 0 deletions src/Illuminate/Console/BufferedConsoleOutput.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Illuminate\Console;

use Symfony\Component\Console\Output\ConsoleOutput;

class BufferedConsoleOutput extends ConsoleOutput
{
/**
* The current buffer.
*
* @var string
*/
protected $buffer = '';

/**
* Empties the buffer and returns its content.
*
* @return string
*/
public function fetch()
{
return tap($this->buffer, function () {
$this->buffer = '';
});
}

/**
* {@inheritdoc}
*/
protected function doWrite(string $message, bool $newline)
{
$this->buffer .= $message;

if ($newline) {
$this->buffer .= \PHP_EOL;
}

return parent::doWrite($message, $newline);
}
}

0 comments on commit 8a14453

Please sign in to comment.