Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Mime] added Headers::toArray() #30484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions 14 src/Symfony/Component/Mime/Header/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,23 @@ public static function isUniqueHeader(string $name): bool
public function toString(): string
{
$string = '';
foreach ($this->toArray() as $str) {
$string .= $str."\r\n";
}

return $string;
}

public function toArray(): array
{
$arr = [];
foreach ($this->getAll() as $header) {
if ('' !== $header->getBodyAsString()) {
$string .= $header->toString()."\r\n";
$arr[] = $header->toString();
}
}

return $string;
return $arr;
}

/**
Expand Down
11 changes: 11 additions & 0 deletions 11 src/Symfony/Component/Mime/Tests/Header/HeadersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,15 @@ public function testHeadersWithoutBodiesAreNotDisplayed()
$headers->addTextHeader('Zip', '');
$this->assertEquals("Foo: bar\r\n", $headers->toString());
}

public function testToArray()
{
$headers = new Headers();
$headers->addIdHeader('Message-ID', 'some@id');
$headers->addTextHeader('Foo', str_repeat('a', 60).pack('C', 0x8F));
$this->assertEquals([
'Message-ID: <some@id>',
"Foo: =?utf-8?Q?aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa?=\r\n =?utf-8?Q?aaaa?=",
], $headers->toArray());
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.