BufferedOutput.php
2 years ago
ConsoleOutput.php
2 years ago
ConsoleOutputInterface.php
2 years ago
ConsoleSectionOutput.php
2 years ago
NullOutput.php
2 years ago
Output.php
2 years ago
OutputInterface.php
2 years ago
StreamOutput.php
2 years ago
TrimmedBufferOutput.php
2 years ago
TrimmedBufferOutput.php
56 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | namespace IAWP_SCOPED\Symfony\Component\Console\Output; |
| 12 | |
| 13 | use IAWP_SCOPED\Symfony\Component\Console\Exception\InvalidArgumentException; |
| 14 | use IAWP_SCOPED\Symfony\Component\Console\Formatter\OutputFormatterInterface; |
| 15 | /** |
| 16 | * A BufferedOutput that keeps only the last N chars. |
| 17 | * |
| 18 | * @author Jérémy Derussé <jeremy@derusse.com> |
| 19 | * @internal |
| 20 | */ |
| 21 | class TrimmedBufferOutput extends Output |
| 22 | { |
| 23 | private $maxLength; |
| 24 | private $buffer = ''; |
| 25 | public function __construct(int $maxLength, ?int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = \false, OutputFormatterInterface $formatter = null) |
| 26 | { |
| 27 | if ($maxLength <= 0) { |
| 28 | throw new InvalidArgumentException(\sprintf('"%s()" expects a strictly positive maxLength. Got %d.', __METHOD__, $maxLength)); |
| 29 | } |
| 30 | parent::__construct($verbosity, $decorated, $formatter); |
| 31 | $this->maxLength = $maxLength; |
| 32 | } |
| 33 | /** |
| 34 | * Empties buffer and returns its content. |
| 35 | * |
| 36 | * @return string |
| 37 | */ |
| 38 | public function fetch() |
| 39 | { |
| 40 | $content = $this->buffer; |
| 41 | $this->buffer = ''; |
| 42 | return $content; |
| 43 | } |
| 44 | /** |
| 45 | * {@inheritdoc} |
| 46 | */ |
| 47 | protected function doWrite(string $message, bool $newline) |
| 48 | { |
| 49 | $this->buffer .= $message; |
| 50 | if ($newline) { |
| 51 | $this->buffer .= \PHP_EOL; |
| 52 | } |
| 53 | $this->buffer = \substr($this->buffer, 0 - $this->maxLength); |
| 54 | } |
| 55 | } |
| 56 |