You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add Recipient value object for named email recipients
Introduce a Recipient class to replace raw string arrays for to, cc,
and bcc fields. This provides a consistent, type-safe API for
associating names with email addresses across all fields and adapters.
BREAKING CHANGE: Email constructor now accepts array<Recipient> for
to, cc, and bcc instead of array<string> and array<array<string,string>>.
Copy file name to clipboardExpand all lines: src/Utopia/Messaging/Messages/Email.php
+8-25Lines changed: 8 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -4,23 +4,22 @@
4
4
5
5
useUtopia\Messaging\Message;
6
6
useUtopia\Messaging\Messages\Email\Attachment;
7
+
useUtopia\Messaging\Messages\Email\Recipient;
7
8
8
9
class Email implements Message
9
10
{
10
11
/**
11
-
* @param array<string> $to The recipients of the email.
12
+
* @param array<Recipient> $to The recipients of the email.
12
13
* @param string $subject The subject of the email.
13
14
* @param string $content The content of the email.
14
15
* @param string $fromName The name of the sender.
15
16
* @param string $fromEmail The email address of the sender.
16
-
* @param array<array<string,string>>|null $cc . The CC recipients of the email. Each recipient should be an array containing a "name" and an "email" key.
17
-
* @param array<array<string,string>>|null $bcc . The BCC recipients of the email. Each recipient should be an array containing a "name" and an "email" key.
18
17
* @param string|null $replyToName The name of the reply to.
19
18
* @param string|null $replyToEmail The email address of the reply to.
19
+
* @param array<Recipient>|null $cc The CC recipients of the email.
20
+
* @param array<Recipient>|null $bcc The BCC recipients of the email.
20
21
* @param array<Attachment>|null $attachments The attachments of the email.
21
22
* @param bool $html Whether the message is HTML or not.
22
-
*
23
-
* @throws \InvalidArgumentException
24
23
*/
25
24
publicfunction__construct(
26
25
privatearray$to,
@@ -42,26 +41,10 @@ public function __construct(
42
41
if (\is_null($this->replyToEmail)) {
43
42
$this->replyToEmail = $this->fromEmail;
44
43
}
45
-
46
-
if (!\is_null($this->cc)) {
47
-
foreach ($this->ccas$recipient) {
48
-
if (!isset($recipient['email'])) {
49
-
thrownew \InvalidArgumentException('Each CC recipient must have at least an email');
50
-
}
51
-
}
52
-
}
53
-
54
-
if (!\is_null($this->bcc)) {
55
-
foreach ($this->bccas$recipient) {
56
-
if (!isset($recipient['email'])) {
57
-
thrownew \InvalidArgumentException('Each BCC recipient must have at least an email');
58
-
}
59
-
}
60
-
}
61
44
}
62
45
63
46
/**
64
-
* @return array<string>
47
+
* @return array<Recipient>
65
48
*/
66
49
publicfunctiongetTo(): array
67
50
{
@@ -99,23 +82,23 @@ public function getReplyToEmail(): string
0 commit comments