1: <?php declare(strict_types=1);
2:
3: namespace Salient\Console\Concept;
4:
5: use Salient\Console\Support\ConsoleMessageFormats as MessageFormats;
6: use Salient\Console\Support\ConsoleTagFormats as TagFormats;
7: use Salient\Console\ConsoleFormatter as Formatter;
8: use Salient\Contract\Console\ConsoleTargetInterface;
9:
10: /**
11: * Base class for console output targets
12: */
13: abstract class ConsoleTarget implements ConsoleTargetInterface
14: {
15: private Formatter $Formatter;
16:
17: /**
18: * @inheritDoc
19: */
20: public function getFormatter(): Formatter
21: {
22: $this->assertIsValid();
23:
24: return $this->Formatter ??= new Formatter(
25: $this->createTagFormats(),
26: $this->createMessageFormats(),
27: fn(): ?int => $this->getWidth(),
28: );
29: }
30:
31: /**
32: * @inheritDoc
33: */
34: public function getWidth(): ?int
35: {
36: $this->assertIsValid();
37:
38: return null;
39: }
40:
41: /**
42: * @inheritDoc
43: */
44: public function close(): void {}
45:
46: protected function assertIsValid(): void {}
47:
48: protected function createTagFormats(): TagFormats
49: {
50: return new TagFormats();
51: }
52:
53: protected function createMessageFormats(): MessageFormats
54: {
55: return new MessageFormats();
56: }
57: }
58: