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\ConsoleInterface as Console; |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | final class ConsoleMessageFormats |
15: | { |
16: | |
17: | private array $Formats = []; |
18: | private MessageFormat $FallbackFormat; |
19: | |
20: | public function __construct(?MessageFormat $fallbackFormat = null) |
21: | { |
22: | $this->FallbackFormat = $fallbackFormat |
23: | ?: MessageFormat::getDefaultMessageFormat(); |
24: | } |
25: | |
26: | |
27: | |
28: | |
29: | |
30: | |
31: | |
32: | |
33: | public function set($level, $type, MessageFormat $format) |
34: | { |
35: | foreach ((array) $level as $level) { |
36: | foreach ((array) $type as $_type) { |
37: | $this->Formats[$level][$_type] = $format; |
38: | } |
39: | } |
40: | |
41: | return $this; |
42: | } |
43: | |
44: | |
45: | |
46: | |
47: | |
48: | |
49: | |
50: | public function get(int $level, $type): MessageFormat |
51: | { |
52: | return $this->Formats[$level][$type] ?? $this->FallbackFormat; |
53: | } |
54: | } |
55: | |