| 199 |
lars |
1 |
<?php namespace Clockwork\Support\Laravel\Console;
|
|
|
2 |
|
|
|
3 |
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
|
|
|
4 |
use Symfony\Component\Console\Formatter\OutputFormatterStyleInterface;
|
|
|
5 |
|
|
|
6 |
// Formatter wrapping around a "real" formatter, capturing the formatted output (Symfony 6.x and later)
|
|
|
7 |
class CapturingFormatter implements OutputFormatterInterface
|
|
|
8 |
{
|
|
|
9 |
protected $formatter;
|
|
|
10 |
|
|
|
11 |
protected $capturedOutput;
|
|
|
12 |
|
|
|
13 |
public function __construct(OutputFormatterInterface $formatter)
|
|
|
14 |
{
|
|
|
15 |
$this->formatter = $formatter;
|
|
|
16 |
}
|
|
|
17 |
|
|
|
18 |
public function capturedOutput()
|
|
|
19 |
{
|
|
|
20 |
$capturedOutput = $this->capturedOutput;
|
|
|
21 |
|
|
|
22 |
$this->capturedOutput = null;
|
|
|
23 |
|
|
|
24 |
return $capturedOutput;
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
public function setDecorated(bool $decorated)
|
|
|
28 |
{
|
|
|
29 |
return $this->formatter->setDecorated($decorated);
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
public function isDecorated(): bool
|
|
|
33 |
{
|
|
|
34 |
return $this->formatter->isDecorated();
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
public function setStyle(string $name, OutputFormatterStyleInterface $style)
|
|
|
38 |
{
|
|
|
39 |
return $this->formatter->setStyle($name, $style);
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
public function hasStyle(string $name): bool
|
|
|
43 |
{
|
|
|
44 |
return $this->formatter->hasStyle($name);
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
public function getStyle(string $name): OutputFormatterStyleInterface
|
|
|
48 |
{
|
|
|
49 |
return $this->formatter->getStyle($name);
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
public function format(?string $message): ?string
|
|
|
53 |
{
|
|
|
54 |
$formatted = $this->formatter->format($message);
|
|
|
55 |
|
|
|
56 |
$this->capturedOutput .= $formatted;
|
|
|
57 |
|
|
|
58 |
return $formatted;
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
public function __call($method, $args)
|
|
|
62 |
{
|
|
|
63 |
return $this->formatter->$method(...$args);
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
public function __clone()
|
|
|
67 |
{
|
|
|
68 |
$this->formatter = clone $this->formatter;
|
|
|
69 |
}
|
|
|
70 |
}
|