| 1: | <?php declare(strict_types=1); |
| 2: | |
| 3: | namespace Salient\Console\Format; |
| 4: | |
| 5: | use Salient\Contract\Console\Format\FormatInterface as Format; |
| 6: | use Salient\Contract\Console\Format\MessageAttributesInterface; |
| 7: | use Salient\Contract\Console\Format\MessageFormatInterface; |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | class MessageFormat implements MessageFormatInterface |
| 13: | { |
| 14: | private Format $Msg1Format; |
| 15: | private Format $Msg2Format; |
| 16: | private Format $PrefixFormat; |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | public function __construct( |
| 22: | Format $msg1Format, |
| 23: | Format $msg2Format, |
| 24: | Format $prefixFormat |
| 25: | ) { |
| 26: | $this->Msg1Format = $msg1Format; |
| 27: | $this->Msg2Format = $msg2Format; |
| 28: | $this->PrefixFormat = $prefixFormat; |
| 29: | } |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | public function apply( |
| 35: | string $msg1, |
| 36: | ?string $msg2, |
| 37: | string $prefix, |
| 38: | MessageAttributesInterface $attributes |
| 39: | ): string { |
| 40: | return ( |
| 41: | $prefix !== '' |
| 42: | ? $this->PrefixFormat->apply($prefix, $attributes->withPrefix()) |
| 43: | : '' |
| 44: | ) . ( |
| 45: | $msg1 !== '' |
| 46: | ? $this->Msg1Format->apply($msg1, $attributes->withMsg1()) |
| 47: | : '' |
| 48: | ) . ( |
| 49: | $msg2 !== null && $msg2 !== '' |
| 50: | ? $this->Msg2Format->apply($msg2, $attributes->withMsg2()) |
| 51: | : '' |
| 52: | ); |
| 53: | } |
| 54: | } |
| 55: | |