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

Commit 3b5f623

Browse filesBrowse files
bug #58764 [Mime] Don't require passing the encoder name to TextPart (javiereguiluz)
This PR was merged into the 7.2 branch. Discussion ---------- [Mime] Don't require passing the encoder name to `TextPart` | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT While preparing this blog post: https://symfony.com/blog/new-in-symfony-7-2-mime-improvements I realized that it's unnecessary to pass the encoder name as the first argument of `TextPart::addEncoder()` because the `ContentEncoderInterface` already requires defining a `getName()` method. Commits ------- 2ce04c8 [Mime] Don't require passig the encoder name to TextPart
2 parents dd8c233 + 2ce04c8 commit 3b5f623
Copy full SHA for 3b5f623

File tree

2 files changed

+16
-8
lines changed
Filter options

2 files changed

+16
-8
lines changed

‎src/Symfony/Component/Mime/Part/TextPart.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mime/Part/TextPart.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,13 @@ private function getEncoder(): ContentEncoderInterface
220220
return self::$encoders[$this->encoding];
221221
}
222222

223-
public static function addEncoder(string $name, ContentEncoderInterface $encoder): void
223+
public static function addEncoder(ContentEncoderInterface $encoder): void
224224
{
225-
if (\in_array($name, self::DEFAULT_ENCODERS, true)) {
225+
if (\in_array($encoder->getName(), self::DEFAULT_ENCODERS, true)) {
226226
throw new InvalidArgumentException('You are not allowed to change the default encoders ("quoted-printable", "base64", and "8bit").');
227227
}
228228

229-
self::$encoders[$name] = $encoder;
229+
self::$encoders[$encoder->getName()] = $encoder;
230230
}
231231

232232
private function chooseEncoding(): string

‎src/Symfony/Component/Mime/Tests/Part/TextPartTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mime/Tests/Part/TextPartTest.php
+13-5Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,29 @@ public function testEncoding()
103103
public function testCustomEncoderNeedsToRegisterFirst()
104104
{
105105
$this->expectException(InvalidArgumentException::class);
106-
$this->expectExceptionMessage('The encoding must be one of "quoted-printable", "base64", "8bit", "exception_test" ("upper_encoder" given).');
107-
TextPart::addEncoder('exception_test', $this->createMock(ContentEncoderInterface::class));
108-
new TextPart('content', 'utf-8', 'plain', 'upper_encoder');
106+
$this->expectExceptionMessage('The encoding must be one of "quoted-printable", "base64", "8bit", "upper_encoder" ("this_encoding_does_not_exist" given).');
107+
108+
$upperEncoder = $this->createMock(ContentEncoderInterface::class);
109+
$upperEncoder->method('getName')->willReturn('upper_encoder');
110+
111+
TextPart::addEncoder($upperEncoder);
112+
new TextPart('content', 'utf-8', 'plain', 'this_encoding_does_not_exist');
109113
}
110114

111115
public function testOverwriteDefaultEncoder()
112116
{
113117
$this->expectException(InvalidArgumentException::class);
114118
$this->expectExceptionMessage('You are not allowed to change the default encoders ("quoted-printable", "base64", and "8bit").');
115-
TextPart::addEncoder('8bit', $this->createMock(ContentEncoderInterface::class));
119+
120+
$base64Encoder = $this->createMock(ContentEncoderInterface::class);
121+
$base64Encoder->method('getName')->willReturn('base64');
122+
123+
TextPart::addEncoder($base64Encoder);
116124
}
117125

118126
public function testCustomEncoding()
119127
{
120-
TextPart::addEncoder('upper_encoder', new class implements ContentEncoderInterface {
128+
TextPart::addEncoder(new class implements ContentEncoderInterface {
121129
public function encodeByteStream($stream, int $maxLineLength = 0): iterable
122130
{
123131
$filter = stream_filter_append($stream, 'string.toupper', \STREAM_FILTER_READ);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.