1: | <?php declare(strict_types=1); |
2: | |
3: | namespace Salient\Console\Target; |
4: | |
5: | use Salient\Console\Format\Formatter; |
6: | use Salient\Contract\Console\Format\FormatterInterface; |
7: | use Salient\Contract\Console\Target\TargetInterface; |
8: | |
9: | |
10: | |
11: | |
12: | abstract class AbstractTarget implements TargetInterface |
13: | { |
14: | private FormatterInterface $Formatter; |
15: | |
16: | |
17: | |
18: | |
19: | final public function getFormatter(): FormatterInterface |
20: | { |
21: | $this->assertIsValid(); |
22: | |
23: | return $this->Formatter ??= $this->createFormatter(); |
24: | } |
25: | |
26: | |
27: | |
28: | |
29: | public function getWidth(): ?int |
30: | { |
31: | $this->assertIsValid(); |
32: | |
33: | return null; |
34: | } |
35: | |
36: | |
37: | |
38: | |
39: | public function close(): void {} |
40: | |
41: | |
42: | |
43: | |
44: | protected function assertIsValid(): void {} |
45: | |
46: | |
47: | |
48: | |
49: | protected function createFormatter(): FormatterInterface |
50: | { |
51: | return new Formatter(null, null, fn() => $this->getWidth()); |
52: | } |
53: | } |
54: | |