minor #32002 [Mailer] made code more robust (fabpot)
This PR was merged into the 4.3 branch.
Discussion
----------
[Mailer] made code more robust
| Q | A
| ------------- | ---
| Branch? | 4.3
| Bug fix? | yes
| New feature? | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks? | no <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass? | yes <!-- please add some, will be required by reviewers -->
| Fixed tickets | n/a
| License | MIT
| Doc PR | n/a
<!--
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.
Additionally (see https://symfony.com/roadmap):
- Bug fixes must be submitted against the lowest maintained branch where they apply
(lowest branches are regularly merged to upper ones so they get the fixes too).
- Features and deprecations must be submitted against branch 4.4.
- Legacy code removals go to the master branch.
-->
Commits
-------
8bdc6596ef
[Mailer] made code more robust
This commit is contained in:
commit
41ff9d31d4
@ -13,7 +13,6 @@ namespace Symfony\Component\Mailer;
|
||||
|
||||
use Symfony\Component\Mailer\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Mime\Address;
|
||||
use Symfony\Component\Mime\NamedAddress;
|
||||
use Symfony\Component\Mime\RawMessage;
|
||||
|
||||
/**
|
||||
@ -42,7 +41,7 @@ class SmtpEnvelope
|
||||
|
||||
public function setSender(Address $sender): void
|
||||
{
|
||||
$this->sender = $sender instanceof NamedAddress ? new Address($sender->getAddress()) : $sender;
|
||||
$this->sender = new Address($sender->getAddress());
|
||||
}
|
||||
|
||||
public function getSender(): Address
|
||||
@ -50,6 +49,9 @@ class SmtpEnvelope
|
||||
return $this->sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Address[] $recipients
|
||||
*/
|
||||
public function setRecipients(array $recipients): void
|
||||
{
|
||||
if (!$recipients) {
|
||||
@ -58,12 +60,10 @@ class SmtpEnvelope
|
||||
|
||||
$this->recipients = [];
|
||||
foreach ($recipients as $recipient) {
|
||||
if ($recipient instanceof NamedAddress) {
|
||||
$recipient = new Address($recipient->getAddress());
|
||||
} elseif (!$recipient instanceof Address) {
|
||||
if (!$recipient instanceof Address) {
|
||||
throw new InvalidArgumentException(sprintf('A recipient must be an instance of "%s" (got "%s").', Address::class, \is_object($recipient) ? \get_class($recipient) : \gettype($recipient)));
|
||||
}
|
||||
$this->recipients[] = $recipient;
|
||||
$this->recipients[] = new Address($recipient->getAddress());
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user