Skip to content

Commit

Permalink
minor #32607 [Mime] rename Headers::getAll() to all() (nicolas-grekas)
Browse files Browse the repository at this point in the history
This PR was merged into the 4.3 branch.

Discussion
----------

[Mime] rename Headers::getAll() to all()

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | yes
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

For consistency with HttpFoundation.
On 4.3 to cut spreading the previous name asap.
Allowed because the component is experimental.

Commits
-------

9252e75 [Mime] rename Headers::getAll() to all()
  • Loading branch information
fabpot committed Jul 18, 2019
2 parents 9c03ab4 + 9252e75 commit 4d7f072
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 29 deletions.
Expand Up @@ -82,7 +82,7 @@ private function getPayload(Email $email, SmtpEnvelope $envelope): array
}

$headersToBypass = ['from', 'to', 'cc', 'bcc', 'subject', 'content-type'];
foreach ($email->getHeaders()->getAll() as $name => $header) {
foreach ($email->getHeaders()->all() as $name => $header) {
if (\in_array($name, $headersToBypass, true)) {
continue;
}
Expand Down
Expand Up @@ -17,7 +17,7 @@
],
"require": {
"php": "^7.1.3",
"symfony/mailer": "^4.3"
"symfony/mailer": "^4.3.3"
},
"require-dev": {
"symfony/http-client": "^4.3"
Expand Down
Expand Up @@ -46,7 +46,7 @@ protected function doSendEmail(Email $email, SmtpEnvelope $envelope): void
{
$body = new FormDataPart($this->getPayload($email, $envelope));
$headers = [];
foreach ($body->getPreparedHeaders()->getAll() as $header) {
foreach ($body->getPreparedHeaders()->all() as $header) {
$headers[] = $header->toString();
}

Expand Down Expand Up @@ -97,7 +97,7 @@ private function getPayload(Email $email, SmtpEnvelope $envelope): array
}

$headersToBypass = ['from', 'to', 'cc', 'bcc', 'subject', 'content-type'];
foreach ($headers->getAll() as $name => $header) {
foreach ($headers->all() as $name => $header) {
if (\in_array($name, $headersToBypass, true)) {
continue;
}
Expand Down
Expand Up @@ -48,7 +48,7 @@ protected function doSend(SentMessage $message): void
'message' => new DataPart($message->toString(), 'message.mime'),
]);
$headers = [];
foreach ($body->getPreparedHeaders()->getAll() as $header) {
foreach ($body->getPreparedHeaders()->all() as $header) {
$headers[] = $header->toString();
}
$endpoint = str_replace(['%domain%', '%region_dot%'], [urlencode($this->domain), 'us' !== ($this->region ?: 'us') ? $this->region.'.' : ''], self::ENDPOINT);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Mailer/Bridge/Mailgun/composer.json
Expand Up @@ -17,7 +17,7 @@
],
"require": {
"php": "^7.1.3",
"symfony/mailer": "^4.3"
"symfony/mailer": "^4.3.3"
},
"require-dev": {
"symfony/http-client": "^4.3"
Expand Down
Expand Up @@ -68,7 +68,7 @@ private function getPayload(Email $email, SmtpEnvelope $envelope): array
];

$headersToBypass = ['from', 'to', 'cc', 'bcc', 'subject', 'content-type', 'sender'];
foreach ($email->getHeaders()->getAll() as $name => $header) {
foreach ($email->getHeaders()->all() as $name => $header) {
if (\in_array($name, $headersToBypass, true)) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Mailer/Bridge/Postmark/composer.json
Expand Up @@ -17,7 +17,7 @@
],
"require": {
"php": "^7.1.3",
"symfony/mailer": "^4.3"
"symfony/mailer": "^4.3.3"
},
"require-dev": {
"symfony/http-client": "^4.3"
Expand Down
Expand Up @@ -82,7 +82,7 @@ private function getPayload(Email $email, SmtpEnvelope $envelope): array
// these headers can't be overwritten according to Sendgrid docs
// see https://developers.pepipost.com/migration-api/new-subpage/email-send
$headersToBypass = ['x-sg-id', 'x-sg-eid', 'received', 'dkim-signature', 'content-transfer-encoding', 'from', 'to', 'cc', 'bcc', 'subject', 'content-type', 'reply-to'];
foreach ($email->getHeaders()->getAll() as $name => $header) {
foreach ($email->getHeaders()->all() as $name => $header) {
if (\in_array($name, $headersToBypass, true)) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Mailer/Bridge/Sendgrid/composer.json
Expand Up @@ -17,7 +17,7 @@
],
"require": {
"php": "^7.1.3",
"symfony/mailer": "^4.3"
"symfony/mailer": "^4.3.3"
},
"require-dev": {
"symfony/http-client": "^4.3"
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Mailer/DelayedSmtpEnvelope.php
Expand Up @@ -73,7 +73,7 @@ private static function getRecipientsFromHeaders(Headers $headers): array
{
$recipients = [];
foreach (['to', 'cc', 'bcc'] as $name) {
foreach ($headers->getAll($name) as $header) {
foreach ($headers->all($name) as $header) {
foreach ($header->getAddresses() as $address) {
$recipients[] = new Address($address->getAddress());
}
Expand Down
Expand Up @@ -53,7 +53,7 @@ private function setHeaders(Message $message): void
}

$headers = $message->getHeaders();
foreach ($this->headers->getAll() as $name => $header) {
foreach ($this->headers->all() as $name => $header) {
if (!$headers->has($name)) {
$headers->add($header);
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Component/Mailer/composer.json
Expand Up @@ -20,16 +20,16 @@
"egulias/email-validator": "^2.0",
"psr/log": "~1.0",
"symfony/event-dispatcher": "^4.3",
"symfony/mime": "^4.3"
"symfony/mime": "^4.3.3"
},
"require-dev": {
"symfony/amazon-mailer": "^4.3",
"symfony/google-mailer": "^4.3",
"symfony/http-client-contracts": "^1.1",
"symfony/mailgun-mailer": "^4.3.2",
"symfony/mailchimp-mailer": "^4.3",
"symfony/postmark-mailer": "^4.3",
"symfony/sendgrid-mailer": "^4.3"
"symfony/mailgun-mailer": "^4.3.3",
"symfony/mailchimp-mailer": "^4.3.3",
"symfony/postmark-mailer": "^4.3.3",
"symfony/sendgrid-mailer": "^4.3.3"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Mailer\\": "" },
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Mime/Header/Headers.php
Expand Up @@ -51,7 +51,7 @@ public function __clone()
public function setMaxLineLength(int $lineLength)
{
$this->lineLength = $lineLength;
foreach ($this->getAll() as $header) {
foreach ($this->all() as $header) {
$header->setMaxLineLength($lineLength);
}
}
Expand Down Expand Up @@ -177,7 +177,7 @@ public function get(string $name): ?HeaderInterface
return array_shift($values);
}

public function getAll(string $name = null): iterable
public function all(string $name = null): iterable
{
if (null === $name) {
foreach ($this->headers as $name => $collection) {
Expand Down Expand Up @@ -220,7 +220,7 @@ public function toString(): string
public function toArray(): array
{
$arr = [];
foreach ($this->getAll() as $header) {
foreach ($this->all() as $header) {
if ('' !== $header->getBodyAsString()) {
$arr[] = $header->toString();
}
Expand Down
16 changes: 8 additions & 8 deletions src/Symfony/Component/Mime/Tests/Header/HeadersTest.php
Expand Up @@ -141,7 +141,7 @@ public function testGetReturnsNullIfHeaderNotSet()
$this->assertNull($headers->get('Message-ID'));
}

public function testGetAllReturnsAllHeadersMatchingName()
public function testAllReturnsAllHeadersMatchingName()
{
$header0 = new UnstructuredHeader('X-Test', 'some@id');
$header1 = new UnstructuredHeader('X-Test', 'other@id');
Expand All @@ -150,10 +150,10 @@ public function testGetAllReturnsAllHeadersMatchingName()
$headers->addTextHeader('X-Test', 'some@id');
$headers->addTextHeader('X-Test', 'other@id');
$headers->addTextHeader('X-Test', 'more@id');
$this->assertEquals([$header0, $header1, $header2], iterator_to_array($headers->getAll('X-Test')));
$this->assertEquals([$header0, $header1, $header2], iterator_to_array($headers->all('X-Test')));
}

public function testGetAllReturnsAllHeadersIfNoArguments()
public function testAllReturnsAllHeadersIfNoArguments()
{
$header0 = new IdentificationHeader('Message-ID', 'some@id');
$header1 = new UnstructuredHeader('Subject', 'thing');
Expand All @@ -162,13 +162,13 @@ public function testGetAllReturnsAllHeadersIfNoArguments()
$headers->addIdHeader('Message-ID', 'some@id');
$headers->addTextHeader('Subject', 'thing');
$headers->addMailboxListHeader('To', [new Address('person@example.org')]);
$this->assertEquals(['message-id' => $header0, 'subject' => $header1, 'to' => $header2], iterator_to_array($headers->getAll()));
$this->assertEquals(['message-id' => $header0, 'subject' => $header1, 'to' => $header2], iterator_to_array($headers->all()));
}

public function testGetAllReturnsEmptyArrayIfNoneSet()
public function testAllReturnsEmptyArrayIfNoneSet()
{
$headers = new Headers();
$this->assertEquals([], iterator_to_array($headers->getAll('Received')));
$this->assertEquals([], iterator_to_array($headers->all('Received')));
}

public function testRemoveRemovesAllHeadersWithName()
Expand Down Expand Up @@ -199,12 +199,12 @@ public function testGetIsNotCaseSensitive()
$this->assertEquals($header, $headers->get('message-id'));
}

public function testGetAllIsNotCaseSensitive()
public function testAllIsNotCaseSensitive()
{
$header = new IdentificationHeader('Message-ID', 'some@id');
$headers = new Headers();
$headers->addIdHeader('Message-ID', 'some@id');
$this->assertEquals([$header], iterator_to_array($headers->getAll('message-id')));
$this->assertEquals([$header], iterator_to_array($headers->all('message-id')));
}

public function testRemoveIsNotCaseSensitive()
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Mime/Tests/MessageTest.php
Expand Up @@ -68,7 +68,7 @@ public function testGetPreparedHeaders()
$message = new Message();
$message->getHeaders()->addMailboxListHeader('From', ['fabien@symfony.com']);
$h = $message->getPreparedHeaders();
$this->assertCount(4, iterator_to_array($h->getAll()));
$this->assertCount(4, iterator_to_array($h->all()));
$this->assertEquals(new MailboxListHeader('From', [new Address('fabien@symfony.com')]), $h->get('From'));
$this->assertEquals(new UnstructuredHeader('MIME-Version', '1.0'), $h->get('mime-version'));
$this->assertTrue($h->has('Message-Id'));
Expand Down

0 comments on commit 4d7f072

Please sign in to comment.