1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kalanis\EmailApi\Basics; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\EmailApi\Interfaces; |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class Content |
11
|
|
|
* @package kalanis\EmaiApi\Basics |
12
|
|
|
* Smallest possible email content |
13
|
|
|
*/ |
14
|
|
|
class Content implements Interfaces\IContent |
15
|
|
|
{ |
16
|
|
|
public string $subject = ''; |
17
|
|
|
public string $body = ''; |
18
|
|
|
public string $tag = ''; |
19
|
|
|
public ?string $plain = null; |
20
|
|
|
public ?string $unsubEmail = null; |
21
|
|
|
public ?string $unsubLink = null; |
22
|
|
|
public bool $unsubByClick = false; |
23
|
|
|
/** @var Interfaces\IContentAttachment[] */ |
24
|
|
|
protected array $attachments = []; |
25
|
|
|
|
26
|
16 |
|
public function setData(string $subject = '', string $body = '', string $tag = ''): self |
27
|
|
|
{ |
28
|
16 |
|
$this->subject = $subject; |
29
|
16 |
|
$this->body = $body; |
30
|
16 |
|
$this->tag = $tag; |
31
|
16 |
|
return $this; |
32
|
|
|
} |
33
|
|
|
|
34
|
2 |
|
public function sanitize(): self |
35
|
|
|
{ |
36
|
2 |
|
$this->subject = strval($this->subject); |
37
|
2 |
|
$this->body = strval($this->body); |
38
|
2 |
|
$this->tag = strval($this->tag); |
39
|
2 |
|
$this->plain = is_null($this->plain) ? null : strval($this->plain); |
40
|
2 |
|
$this->unsubEmail = is_null($this->unsubEmail) ? null : strval($this->unsubEmail); |
41
|
2 |
|
$this->unsubLink = is_null($this->unsubLink) ? null : strval($this->unsubLink); |
42
|
2 |
|
$this->unsubByClick = boolval($this->unsubByClick); |
43
|
2 |
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
2 |
|
public function getSubject(): string |
47
|
|
|
{ |
48
|
2 |
|
return strval($this->subject); |
49
|
|
|
} |
50
|
|
|
|
51
|
4 |
|
public function getHtmlBody(): string |
52
|
|
|
{ |
53
|
4 |
|
return strval($this->body); |
54
|
|
|
} |
55
|
|
|
|
56
|
1 |
|
public function getPlainBody(): ?string |
57
|
|
|
{ |
58
|
1 |
|
return $this->plain; |
59
|
|
|
} |
60
|
|
|
|
61
|
2 |
|
public function getTag(): string |
62
|
|
|
{ |
63
|
2 |
|
return strval($this->tag); |
64
|
|
|
} |
65
|
|
|
|
66
|
1 |
|
public function getUnsubscribeEmail(): ?string |
67
|
|
|
{ |
68
|
1 |
|
return $this->unsubEmail; |
69
|
|
|
} |
70
|
|
|
|
71
|
1 |
|
public function getUnsubscribeLink(): ?string |
72
|
|
|
{ |
73
|
1 |
|
return $this->unsubLink; |
74
|
|
|
} |
75
|
|
|
|
76
|
1 |
|
public function canUnsubscribeOneClick(): bool |
77
|
|
|
{ |
78
|
1 |
|
return boolval($this->unsubByClick); |
79
|
|
|
} |
80
|
|
|
|
81
|
2 |
|
public function addAttachment(Interfaces\IContentAttachment $attachment): self |
82
|
|
|
{ |
83
|
2 |
|
$this->attachments[] = $attachment; |
84
|
2 |
|
return $this; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return array<Interfaces\IContentAttachment> |
89
|
|
|
*/ |
90
|
2 |
|
public function getAttachments(): array |
91
|
|
|
{ |
92
|
2 |
|
return $this->attachments; |
93
|
|
|
} |
94
|
|
|
|
95
|
1 |
|
public function resetAttachments(): self |
96
|
|
|
{ |
97
|
1 |
|
$this->attachments = []; |
98
|
1 |
|
return $this; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|