PluginProbe
Depicter — Popup & Slider Builder / 1.3.3
Depicter — Popup & Slider Builder v1.3.3
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / vendor / symfony / console / Output / TrimmedBufferOutput.php

TrimmedBufferOutput.php in Depicter — Popup & Slider Builder 1.3.3, at vendor/symfony/console/Output/TrimmedBufferOutput.php

68 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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
12 namespace Symfony\Component\Console\Output;
13
14 use Symfony\Component\Console\Exception\InvalidArgumentException;
15 use Symfony\Component\Console\Formatter\OutputFormatterInterface;
16
17 /**
18 * A BufferedOutput that keeps only the last N chars.
19 *
20 * @author Jérémy Derussé <jeremy@derusse.com>
21 */
22 class TrimmedBufferOutput extends Output
23 {
24 private $maxLength;
25 private $buffer = '';
26
27 public function __construct(
28 int $maxLength,
29 ?int $verbosity = self::VERBOSITY_NORMAL,
30 bool $decorated = false,
31 OutputFormatterInterface $formatter = null
32 ) {
33 if ($maxLength <= 0) {
34 throw new InvalidArgumentException(sprintf('"%s()" expects a strictly positive maxLength. Got %d.', __METHOD__, $maxLength));
35 }
36
37 parent::__construct($verbosity, $decorated, $formatter);
38 $this->maxLength = $maxLength;
39 }
40
41 /**
42 * Empties buffer and returns its content.
43 *
44 * @return string
45 */
46 public function fetch()
47 {
48 $content = $this->buffer;
49 $this->buffer = '';
50
51 return $content;
52 }
53
54 /**
55 * {@inheritdoc}
56 */
57 protected function doWrite($message, $newline)
58 {
59 $this->buffer .= $message;
60
61 if ($newline) {
62 $this->buffer .= \PHP_EOL;
63 }
64
65 $this->buffer = substr($this->buffer, 0 - $this->maxLength);
66 }
67 }
68