|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Genkgo\Mail; |
|
5
|
|
|
|
|
6
|
|
|
use Genkgo\Mail\Mime\EmbeddedImage; |
|
7
|
|
|
use Genkgo\Mail\Mime\PartInterface; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* This class is superseded by MessageBodyCollection. Since there is no need to remove or deprecate this |
|
11
|
|
|
* class, it will remain part of the package. |
|
12
|
|
|
*/ |
|
13
|
|
|
final class FormattedMessageFactory |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var MessageBodyCollection |
|
17
|
|
|
*/ |
|
18
|
|
|
private $messageBody; |
|
19
|
|
|
|
|
20
|
|
|
public function __construct() |
|
21
|
|
|
{ |
|
22
|
|
|
$this->messageBody = new MessageBodyCollection(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param string $html |
|
27
|
|
|
* @return FormattedMessageFactory |
|
28
|
|
|
*/ |
|
29
|
|
|
public function withHtml(string $html): FormattedMessageFactory |
|
30
|
|
|
{ |
|
31
|
|
|
$clone = clone $this; |
|
32
|
|
|
$clone->messageBody = $clone->messageBody |
|
33
|
|
|
->withHtml($html) |
|
34
|
|
|
->withAlternativeText(AlternativeText::fromHtml($html)); |
|
35
|
|
|
return $clone; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param string $html |
|
40
|
3 |
|
* @return FormattedMessageFactory |
|
41
|
|
|
*/ |
|
42
|
3 |
|
public function withHtmlAndNoGeneratedAlternativeText(string $html): FormattedMessageFactory |
|
43
|
3 |
|
{ |
|
44
|
3 |
|
$clone = clone $this; |
|
45
|
3 |
|
$clone->messageBody = $clone->messageBody->withHtml($html); |
|
46
|
|
|
return $clone; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param AlternativeText $text |
|
51
|
|
|
* @return FormattedMessageFactory |
|
52
|
2 |
|
*/ |
|
53
|
|
|
public function withAlternativeText(AlternativeText $text): FormattedMessageFactory |
|
54
|
2 |
|
{ |
|
55
|
2 |
|
$clone = clone $this; |
|
56
|
2 |
|
$clone->messageBody = $clone->messageBody->withAlternativeText($text); |
|
57
|
|
|
return $clone; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param PartInterface $part |
|
62
|
|
|
* @return FormattedMessageFactory |
|
63
|
2 |
|
*/ |
|
64
|
|
|
public function withAttachment(PartInterface $part): FormattedMessageFactory |
|
65
|
2 |
|
{ |
|
66
|
2 |
|
$clone = clone $this; |
|
67
|
2 |
|
$clone->messageBody = $clone->messageBody->withAttachment($part); |
|
68
|
|
|
return $clone; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param EmbeddedImage $embeddedImage |
|
73
|
|
|
* @return FormattedMessageFactory |
|
74
|
5 |
|
*/ |
|
75
|
|
|
public function withEmbeddedImage(EmbeddedImage $embeddedImage): FormattedMessageFactory |
|
76
|
|
|
{ |
|
77
|
5 |
|
$clone = clone $this; |
|
78
|
4 |
|
$clone->messageBody = $clone->messageBody->withEmbeddedImage($embeddedImage); |
|
79
|
1 |
|
return $clone; |
|
80
|
4 |
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
2 |
|
* @return MessageInterface |
|
84
|
1 |
|
*/ |
|
85
|
1 |
|
public function createMessage(): MessageInterface |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->messageBody->createMessage(); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|