Skip to content

Commit 652dc7d

Browse files
committed
minor #48060 [Mime] rename Part/BodyFile to Part/File (nicolas-grekas)
This PR was merged into the 6.2 branch. Discussion ---------- [Mime] rename Part/BodyFile to Part/File | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Was proposed during a chat within the core-team. /cc `@javiereguiluz` Commits ------- 5e2a2ef [Mime] rename Part/BodyFile to Part/File
2 parents 929d5f4 + 5e2a2ef commit 652dc7d

File tree

8 files changed

+25
-25
lines changed

8 files changed

+25
-25
lines changed

src/Symfony/Bridge/Twig/Mime/WrappedTemplatedEmail.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
namespace Symfony\Bridge\Twig\Mime;
1313

1414
use Symfony\Component\Mime\Address;
15-
use Symfony\Component\Mime\Part\BodyFile;
1615
use Symfony\Component\Mime\Part\DataPart;
16+
use Symfony\Component\Mime\Part\File;
1717
use Twig\Environment;
1818

1919
/**
@@ -40,7 +40,7 @@ public function toName(): string
4040
public function image(string $image, string $contentType = null): string
4141
{
4242
$file = $this->twig->getLoader()->getSourceContext($image);
43-
$body = $file->getPath() ? new BodyFile($file->getPath()) : $file->getCode();
43+
$body = $file->getPath() ? new File($file->getPath()) : $file->getCode();
4444
$this->message->addPart((new DataPart($body, $image, $contentType))->asInline());
4545

4646
return 'cid:'.$image;
@@ -49,7 +49,7 @@ public function image(string $image, string $contentType = null): string
4949
public function attach(string $file, string $name = null, string $contentType = null): void
5050
{
5151
$file = $this->twig->getLoader()->getSourceContext($file);
52-
$body = $file->getPath() ? new BodyFile($file->getPath()) : $file->getCode();
52+
$body = $file->getPath() ? new File($file->getPath()) : $file->getCode();
5353
$this->message->addPart(new DataPart($body, $name, $contentType));
5454
}
5555

src/Symfony/Component/Mailer/Tests/Transport/Smtp/SmtpTransportTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
use Symfony\Component\Mime\Address;
2222
use Symfony\Component\Mime\Email;
2323
use Symfony\Component\Mime\Exception\InvalidArgumentException;
24-
use Symfony\Component\Mime\Part\BodyFile;
2524
use Symfony\Component\Mime\Part\DataPart;
25+
use Symfony\Component\Mime\Part\File;
2626
use Symfony\Component\Mime\RawMessage;
2727

2828
/**
@@ -105,7 +105,7 @@ public function testSendInvalidMessage()
105105
$message = new Email();
106106
$message->to('recipient@example.org');
107107
$message->from('sender@example.org');
108-
$message->addPart(new DataPart(new BodyFile('/does_not_exists')));
108+
$message->addPart(new DataPart(new File('/does_not_exists')));
109109

110110
try {
111111
$transport->send($message);

src/Symfony/Component/Mime/Email.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
use Symfony\Component\Mime\Exception\LogicException;
1515
use Symfony\Component\Mime\Part\AbstractPart;
16-
use Symfony\Component\Mime\Part\BodyFile;
1716
use Symfony\Component\Mime\Part\DataPart;
17+
use Symfony\Component\Mime\Part\File;
1818
use Symfony\Component\Mime\Part\Multipart\AlternativePart;
1919
use Symfony\Component\Mime\Part\Multipart\MixedPart;
2020
use Symfony\Component\Mime\Part\Multipart\RelatedPart;
@@ -335,7 +335,7 @@ public function attach($body, string $name = null, string $contentType = null):
335335
*/
336336
public function attachFromPath(string $path, string $name = null, string $contentType = null): static
337337
{
338-
return $this->addPart(new DataPart(new BodyFile($path), $name, $contentType));
338+
return $this->addPart(new DataPart(new File($path), $name, $contentType));
339339
}
340340

341341
/**
@@ -353,7 +353,7 @@ public function embed($body, string $name = null, string $contentType = null): s
353353
*/
354354
public function embedFromPath(string $path, string $name = null, string $contentType = null): static
355355
{
356-
return $this->addPart((new DataPart(new BodyFile($path), $name, $contentType))->asInline());
356+
return $this->addPart((new DataPart(new File($path), $name, $contentType))->asInline());
357357
}
358358

359359
/**

src/Symfony/Component/Mime/Part/DataPart.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ class DataPart extends TextPart
2727
private $cid;
2828

2929
/**
30-
* @param resource|string|BodyFile $body Use a BodyFile instance to defer loading the file until rendering
30+
* @param resource|string|File $body Use a File instance to defer loading the file until rendering
3131
*/
3232
public function __construct($body, string $filename = null, string $contentType = null, string $encoding = null)
3333
{
3434
unset($this->_parent);
3535

36-
if ($body instanceof BodyFile && !$filename) {
36+
if ($body instanceof File && !$filename) {
3737
$filename = basename($body->getPath());
3838
}
3939

4040
if (null === $contentType) {
41-
$contentType = $body instanceof BodyFile ? $body->getContentType() : 'application/octet-stream';
41+
$contentType = $body instanceof File ? $body->getContentType() : 'application/octet-stream';
4242
}
4343
[$this->mediaType, $subtype] = explode('/', $contentType);
4444

@@ -53,7 +53,7 @@ public function __construct($body, string $filename = null, string $contentType
5353

5454
public static function fromPath(string $path, string $name = null, string $contentType = null): self
5555
{
56-
return new self(new BodyFile($path), $name, $contentType);
56+
return new self(new File($path), $name, $contentType);
5757
}
5858

5959
/**

src/Symfony/Component/Mime/Part/BodyFile.php renamed to src/Symfony/Component/Mime/Part/File.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* @author Fabien Potencier <fabien@symfony.com>
1818
*/
19-
class BodyFile
19+
class File
2020
{
2121
private static $mimeTypes;
2222

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,19 @@ class TextPart extends AbstractPart
4040
private $seekable;
4141

4242
/**
43-
* @param resource|string|BodyFile $body Use a BodyFile instance to defer loading the file until rendering
43+
* @param resource|string|File $body Use a File instance to defer loading the file until rendering
4444
*/
4545
public function __construct($body, ?string $charset = 'utf-8', string $subtype = 'plain', string $encoding = null)
4646
{
4747
unset($this->_headers);
4848

4949
parent::__construct();
5050

51-
if (!\is_string($body) && !\is_resource($body) && !$body instanceof BodyFile) {
52-
throw new \TypeError(sprintf('The body of "%s" must be a string, a resource, or an instance of "%s" (got "%s").', self::class, BodyFile::class, get_debug_type($body)));
51+
if (!\is_string($body) && !\is_resource($body) && !$body instanceof File) {
52+
throw new \TypeError(sprintf('The body of "%s" must be a string, a resource, or an instance of "%s" (got "%s").', self::class, File::class, get_debug_type($body)));
5353
}
5454

55-
if ($body instanceof BodyFile) {
55+
if ($body instanceof File) {
5656
$path = $body->getPath();
5757
if ((is_file($path) && !is_readable($path)) || is_dir($path)) {
5858
throw new InvalidArgumentException(sprintf('Path "%s" is not readable.', $path));
@@ -118,7 +118,7 @@ public function getName(): ?string
118118

119119
public function getBody(): string
120120
{
121-
if ($this->body instanceof BodyFile) {
121+
if ($this->body instanceof File) {
122122
return file_get_contents($this->body->getPath());
123123
}
124124

@@ -140,7 +140,7 @@ public function bodyToString(): string
140140

141141
public function bodyToIterable(): iterable
142142
{
143-
if ($this->body instanceof BodyFile) {
143+
if ($this->body instanceof File) {
144144
$path = $this->body->getPath();
145145
if (false === $handle = @fopen($path, 'r', false)) {
146146
throw new InvalidArgumentException(sprintf('Unable to open path "%s".', $path));

src/Symfony/Component/Mime/Tests/EmailTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
use PHPUnit\Framework\TestCase;
1616
use Symfony\Component\Mime\Address;
1717
use Symfony\Component\Mime\Email;
18-
use Symfony\Component\Mime\Part\BodyFile;
1918
use Symfony\Component\Mime\Part\DataPart;
19+
use Symfony\Component\Mime\Part\File;
2020
use Symfony\Component\Mime\Part\Multipart\AlternativePart;
2121
use Symfony\Component\Mime\Part\Multipart\MixedPart;
2222
use Symfony\Component\Mime\Part\Multipart\RelatedPart;
@@ -463,8 +463,8 @@ public function testAttachments()
463463
$att = DataPart::fromPath($name, 'test');
464464
$inline = DataPart::fromPath($name, 'test')->asInline();
465465
$e = new Email();
466-
$e->addPart(new DataPart(new BodyFile($name)));
467-
$e->addPart((new DataPart(new BodyFile($name)))->asInline());
466+
$e->addPart(new DataPart(new File($name)));
467+
$e->addPart((new DataPart(new File($name)))->asInline());
468468
$this->assertEquals([$att->bodyToString(), $inline->bodyToString()], array_map(function (DataPart $a) { return $a->bodyToString(); }, $e->getAttachments()));
469469
$this->assertEquals([$att->getPreparedHeaders(), $inline->getPreparedHeaders()], array_map(function (DataPart $a) { return $a->getPreparedHeaders(); }, $e->getAttachments()));
470470
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Symfony\Component\Mime\Header\Headers;
1616
use Symfony\Component\Mime\Header\ParameterizedHeader;
1717
use Symfony\Component\Mime\Header\UnstructuredHeader;
18-
use Symfony\Component\Mime\Part\BodyFile;
18+
use Symfony\Component\Mime\Part\File;
1919
use Symfony\Component\Mime\Part\TextPart;
2020

2121
class TextPartTest extends TestCase
@@ -47,9 +47,9 @@ public function testConstructorWithResource()
4747
fclose($f);
4848
}
4949

50-
public function testConstructorWithBodyFile()
50+
public function testConstructorWithFile()
5151
{
52-
$p = new TextPart(new BodyFile(\dirname(__DIR__).'/Fixtures/content.txt'));
52+
$p = new TextPart(new File(\dirname(__DIR__).'/Fixtures/content.txt'));
5353
$this->assertSame('content', $p->getBody());
5454
$this->assertSame('content', $p->bodyToString());
5555
$this->assertSame('content', implode('', iterator_to_array($p->bodyToIterable())));

0 commit comments

Comments
 (0)