55namespace PhpList \Core \Domain \Model \Messaging \Message ;
66
77use Doctrine \ORM \Mapping as ORM ;
8+ use InvalidArgumentException ;
89
910#[ORM \Embeddable]
1011class MessageFormat
@@ -16,36 +17,43 @@ class MessageFormat
1617 private ?string $ sendFormat = null ;
1718
1819 #[ORM \Column(name: 'astext ' , type: 'integer ' , options: ['default ' => 0 ])]
19- private bool $ asText ;
20+ private bool $ asText = false ;
2021
2122 #[ORM \Column(name: 'ashtml ' , type: 'integer ' , options: ['default ' => 0 ])]
22- private bool $ asHtml ;
23+ private bool $ asHtml = false ;
2324
2425 #[ORM \Column(name: 'aspdf ' , type: 'integer ' , options: ['default ' => 0 ])]
25- private bool $ asPdf ;
26+ private bool $ asPdf = false ;
2627
2728 #[ORM \Column(name: 'astextandhtml ' , type: 'integer ' , options: ['default ' => 0 ])]
28- private bool $ asTextAndHtml ;
29+ private bool $ asTextAndHtml = false ;
2930
3031 #[ORM \Column(name: 'astextandpdf ' , type: 'integer ' , options: ['default ' => 0 ])]
31- private bool $ asTextAndPdf ;
32+ private bool $ asTextAndPdf = false ;
33+
34+ public const FORMAT_TEXT = 'text ' ;
35+ public const FORMAT_HTML = 'html ' ;
36+ public const FORMAT_PDF = 'pdf ' ;
3237
3338 public function __construct (
3439 bool $ htmlFormatted ,
35- string $ sendFormat = null ,
36- bool $ asText = false ,
37- bool $ asHtml = false ,
38- bool $ asPdf = false ,
39- bool $ asTextAndHtml = false ,
40- bool $ asTextAndPdf = false ,
40+ ?string $ sendFormat ,
41+ array $ formatOptions = []
4142 ) {
4243 $ this ->htmlFormatted = $ htmlFormatted ;
4344 $ this ->sendFormat = $ sendFormat ;
44- $ this ->asText = $ asText ;
45- $ this ->asHtml = $ asHtml ;
46- $ this ->asPdf = $ asPdf ;
47- $ this ->asTextAndHtml = $ asTextAndHtml ;
48- $ this ->asTextAndPdf = $ asTextAndPdf ;
45+
46+ foreach ($ formatOptions as $ option ) {
47+ match ($ option ) {
48+ self ::FORMAT_TEXT => $ this ->asText = true ,
49+ self ::FORMAT_HTML => $ this ->asHtml = true ,
50+ self ::FORMAT_PDF => $ this ->asPdf = true ,
51+ default => throw new InvalidArgumentException ('Invalid format option: ' . $ option )
52+ };
53+ }
54+
55+ $ this ->asTextAndHtml = $ this ->asText && $ this ->asHtml ;
56+ $ this ->asTextAndPdf = $ this ->asText && $ this ->asPdf ;
4957 }
5058
5159 public function isHtmlFormatted (): bool
0 commit comments