1: | <?php declare(strict_types=1); |
2: | |
3: | namespace Salient\Console\Support; |
4: | |
5: | use Salient\Console\Support\ConsoleMessageFormat as MessageFormat; |
6: | use Salient\Contract\Console\ConsoleMessageType as MessageType; |
7: | use Salient\Contract\Core\MessageLevel as Level; |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | final class ConsoleMessageFormats |
16: | { |
17: | |
18: | private array $Formats = []; |
19: | private MessageFormat $FallbackFormat; |
20: | |
21: | public function __construct(?MessageFormat $fallbackFormat = null) |
22: | { |
23: | $this->FallbackFormat = $fallbackFormat |
24: | ?: MessageFormat::getDefaultMessageFormat(); |
25: | } |
26: | |
27: | |
28: | |
29: | |
30: | |
31: | |
32: | |
33: | |
34: | public function set($level, $type, MessageFormat $format) |
35: | { |
36: | foreach ((array) $level as $level) { |
37: | foreach ((array) $type as $_type) { |
38: | $this->Formats[$level][$_type] = $format; |
39: | } |
40: | } |
41: | |
42: | return $this; |
43: | } |
44: | |
45: | |
46: | |
47: | |
48: | |
49: | |
50: | |
51: | public function get($level, $type): MessageFormat |
52: | { |
53: | return $this->Formats[$level][$type] ?? $this->FallbackFormat; |
54: | } |
55: | } |
56: | |