5
5
namespace PhpList \Core \Domain \Model \Messaging \Message ;
6
6
7
7
use Doctrine \ORM \Mapping as ORM ;
8
+ use InvalidArgumentException ;
8
9
9
10
#[ORM \Embeddable]
10
11
class MessageFormat
@@ -16,36 +17,43 @@ class MessageFormat
16
17
private ?string $ sendFormat = null ;
17
18
18
19
#[ORM \Column(name: 'astext ' , type: 'integer ' , options: ['default ' => 0 ])]
19
- private bool $ asText ;
20
+ private bool $ asText = false ;
20
21
21
22
#[ORM \Column(name: 'ashtml ' , type: 'integer ' , options: ['default ' => 0 ])]
22
- private bool $ asHtml ;
23
+ private bool $ asHtml = false ;
23
24
24
25
#[ORM \Column(name: 'aspdf ' , type: 'integer ' , options: ['default ' => 0 ])]
25
- private bool $ asPdf ;
26
+ private bool $ asPdf = false ;
26
27
27
28
#[ORM \Column(name: 'astextandhtml ' , type: 'integer ' , options: ['default ' => 0 ])]
28
- private bool $ asTextAndHtml ;
29
+ private bool $ asTextAndHtml = false ;
29
30
30
31
#[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 ' ;
32
37
33
38
public function __construct (
34
39
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 = []
41
42
) {
42
43
$ this ->htmlFormatted = $ htmlFormatted ;
43
44
$ 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 ;
49
57
}
50
58
51
59
public function isHtmlFormatted (): bool
0 commit comments