minor #30480 [Mime] Use "yield from" when possible (fabpot)
This PR was merged into the 4.3-dev branch.
Discussion
----------
[Mime] Use "yield from" when possible
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks? | no <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to 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
Commits
-------
df1b627417
[Mime] used yield-from when possible
This commit is contained in:
commit
ba727ec509
@ -122,9 +122,7 @@ class Message extends RawMessage
|
|||||||
}
|
}
|
||||||
|
|
||||||
yield $this->getPreparedHeaders()->toString();
|
yield $this->getPreparedHeaders()->toString();
|
||||||
foreach ($body->toIterable() as $chunk) {
|
yield from $body->toIterable();
|
||||||
yield $chunk;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function generateMessageId(string $email): string
|
private function generateMessageId(string $email): string
|
||||||
|
@ -81,9 +81,7 @@ abstract class AbstractMultipartPart extends AbstractPart
|
|||||||
|
|
||||||
foreach ($parts as $part) {
|
foreach ($parts as $part) {
|
||||||
yield '--'.$this->getBoundary()."\r\n";
|
yield '--'.$this->getBoundary()."\r\n";
|
||||||
foreach ($part->toIterable() as $chunk) {
|
yield from $part->toIterable();
|
||||||
yield $chunk;
|
|
||||||
}
|
|
||||||
yield "\r\n";
|
yield "\r\n";
|
||||||
}
|
}
|
||||||
yield '--'.$this->getBoundary()."--\r\n";
|
yield '--'.$this->getBoundary()."--\r\n";
|
||||||
|
@ -49,9 +49,7 @@ abstract class AbstractPart
|
|||||||
{
|
{
|
||||||
yield $this->getPreparedHeaders()->toString();
|
yield $this->getPreparedHeaders()->toString();
|
||||||
yield "\r\n";
|
yield "\r\n";
|
||||||
foreach ($this->bodyToIterable() as $chunk) {
|
yield from $this->bodyToIterable();
|
||||||
yield $chunk;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract public function bodyToString(): string;
|
abstract public function bodyToString(): string;
|
||||||
|
@ -118,9 +118,7 @@ class TextPart extends AbstractPart
|
|||||||
if (stream_get_meta_data($this->body)['seekable'] ?? false) {
|
if (stream_get_meta_data($this->body)['seekable'] ?? false) {
|
||||||
rewind($this->body);
|
rewind($this->body);
|
||||||
}
|
}
|
||||||
foreach ($this->getEncoder()->encodeByteStream($this->body) as $chunk) {
|
yield from $this->getEncoder()->encodeByteStream($this->body);
|
||||||
yield $chunk;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
yield $this->getEncoder()->encodeString($this->body);
|
yield $this->getEncoder()->encodeString($this->body);
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ class RawMessage
|
|||||||
return $this->message;
|
return $this->message;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->message = implode('', iterator_to_array($this->message));
|
return $this->message = implode('', iterator_to_array($this->message, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toIterable(): iterable
|
public function toIterable(): iterable
|
||||||
|
@ -131,7 +131,7 @@ Content-Transfer-Encoding: quoted-printable
|
|||||||
|
|
||||||
EOF;
|
EOF;
|
||||||
$this->assertStringMatchesFormat($expected, str_replace("\r\n", "\n", $message->toString()));
|
$this->assertStringMatchesFormat($expected, str_replace("\r\n", "\n", $message->toString()));
|
||||||
$this->assertStringMatchesFormat($expected, str_replace("\r\n", "\n", implode('', iterator_to_array($message->toIterable()))));
|
$this->assertStringMatchesFormat($expected, str_replace("\r\n", "\n", implode('', iterator_to_array($message->toIterable(), false))));
|
||||||
|
|
||||||
$message = new Message(null, new TextPart('content'));
|
$message = new Message(null, new TextPart('content'));
|
||||||
$message->getHeaders()->addMailboxListHeader('From', ['fabien@symfony.com']);
|
$message->getHeaders()->addMailboxListHeader('From', ['fabien@symfony.com']);
|
||||||
@ -146,6 +146,6 @@ Content-Transfer-Encoding: quoted-printable
|
|||||||
content
|
content
|
||||||
EOF;
|
EOF;
|
||||||
$this->assertStringMatchesFormat($expected, str_replace("\r\n", "\n", $message->toString()));
|
$this->assertStringMatchesFormat($expected, str_replace("\r\n", "\n", $message->toString()));
|
||||||
$this->assertStringMatchesFormat($expected, str_replace("\r\n", "\n", implode('', iterator_to_array($message->toIterable()))));
|
$this->assertStringMatchesFormat($expected, str_replace("\r\n", "\n", implode('', iterator_to_array($message->toIterable(), false))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user