Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit3b5f623

Browse files
bug#58764 [Mime] Don't require passing the encoder name toTextPart (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 | MITWhile preparing this blog post:https://symfony.com/blog/new-in-symfony-7-2-mime-improvementsI 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 parentsdd8c233 +2ce04c8 commit3b5f623

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,13 @@ private function getEncoder(): ContentEncoderInterface
220220
returnself::$encoders[$this->encoding];
221221
}
222222

223-
publicstaticfunctionaddEncoder(string$name,ContentEncoderInterface$encoder):void
223+
publicstaticfunctionaddEncoder(ContentEncoderInterface$encoder):void
224224
{
225-
if (\in_array($name,self::DEFAULT_ENCODERS,true)) {
225+
if (\in_array($encoder->getName(),self::DEFAULT_ENCODERS,true)) {
226226
thrownewInvalidArgumentException('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
privatefunctionchooseEncoding():string

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,29 @@ public function testEncoding()
103103
publicfunctiontestCustomEncoderNeedsToRegisterFirst()
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-
newTextPart('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+
newTextPart('content','utf-8','plain','this_encoding_does_not_exist');
109113
}
110114

111115
publicfunctiontestOverwriteDefaultEncoder()
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
publicfunctiontestCustomEncoding()
119127
{
120-
TextPart::addEncoder('upper_encoder',newclassimplements ContentEncoderInterface {
128+
TextPart::addEncoder(newclassimplements ContentEncoderInterface {
121129
publicfunctionencodeByteStream($stream,int$maxLineLength =0):iterable
122130
{
123131
$filter =stream_filter_append($stream,'string.toupper', \STREAM_FILTER_READ);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp