BufferedOutput.php 838 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Console\Output;
  11. /**
  12. * @author Jean-François Simon <contact@jfsimon.fr>
  13. */
  14. class BufferedOutput extends Output
  15. {
  16. private string $buffer = '';
  17. /**
  18. * Empties buffer and returns its content.
  19. */
  20. public function fetch(): string
  21. {
  22. $content = $this->buffer;
  23. $this->buffer = '';
  24. return $content;
  25. }
  26. /**
  27. * @return void
  28. */
  29. protected function doWrite(string $message, bool $newline)
  30. {
  31. $this->buffer .= $message;
  32. if ($newline) {
  33. $this->buffer .= \PHP_EOL;
  34. }
  35. }
  36. }