From 5e2a2efec1738018b4776406e47108023fae1f88 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 31 Oct 2022 19:29:16 +0100 Subject: [PATCH] [Mime] rename Part/BodyFile to Part/File --- .../Bridge/Twig/Mime/WrappedTemplatedEmail.php | 6 +++--- .../Tests/Transport/Smtp/SmtpTransportTest.php | 4 ++-- src/Symfony/Component/Mime/Email.php | 6 +++--- src/Symfony/Component/Mime/Part/DataPart.php | 8 ++++---- .../Component/Mime/Part/{BodyFile.php => File.php} | 2 +- src/Symfony/Component/Mime/Part/TextPart.php | 12 ++++++------ src/Symfony/Component/Mime/Tests/EmailTest.php | 6 +++--- .../Component/Mime/Tests/Part/TextPartTest.php | 6 +++--- 8 files changed, 25 insertions(+), 25 deletions(-) rename src/Symfony/Component/Mime/Part/{BodyFile.php => File.php} (98%) diff --git a/src/Symfony/Bridge/Twig/Mime/WrappedTemplatedEmail.php b/src/Symfony/Bridge/Twig/Mime/WrappedTemplatedEmail.php index 1d3b92d6dbdd6..d8a5eea97be16 100644 --- a/src/Symfony/Bridge/Twig/Mime/WrappedTemplatedEmail.php +++ b/src/Symfony/Bridge/Twig/Mime/WrappedTemplatedEmail.php @@ -12,8 +12,8 @@ namespace Symfony\Bridge\Twig\Mime; use Symfony\Component\Mime\Address; -use Symfony\Component\Mime\Part\BodyFile; use Symfony\Component\Mime\Part\DataPart; +use Symfony\Component\Mime\Part\File; use Twig\Environment; /** @@ -40,7 +40,7 @@ public function toName(): string public function image(string $image, string $contentType = null): string { $file = $this->twig->getLoader()->getSourceContext($image); - $body = $file->getPath() ? new BodyFile($file->getPath()) : $file->getCode(); + $body = $file->getPath() ? new File($file->getPath()) : $file->getCode(); $this->message->addPart((new DataPart($body, $image, $contentType))->asInline()); return 'cid:'.$image; @@ -49,7 +49,7 @@ public function image(string $image, string $contentType = null): string public function attach(string $file, string $name = null, string $contentType = null): void { $file = $this->twig->getLoader()->getSourceContext($file); - $body = $file->getPath() ? new BodyFile($file->getPath()) : $file->getCode(); + $body = $file->getPath() ? new File($file->getPath()) : $file->getCode(); $this->message->addPart(new DataPart($body, $name, $contentType)); } diff --git a/src/Symfony/Component/Mailer/Tests/Transport/Smtp/SmtpTransportTest.php b/src/Symfony/Component/Mailer/Tests/Transport/Smtp/SmtpTransportTest.php index 42a76e6d80a27..9bad860829d85 100644 --- a/src/Symfony/Component/Mailer/Tests/Transport/Smtp/SmtpTransportTest.php +++ b/src/Symfony/Component/Mailer/Tests/Transport/Smtp/SmtpTransportTest.php @@ -21,8 +21,8 @@ use Symfony\Component\Mime\Address; use Symfony\Component\Mime\Email; use Symfony\Component\Mime\Exception\InvalidArgumentException; -use Symfony\Component\Mime\Part\BodyFile; use Symfony\Component\Mime\Part\DataPart; +use Symfony\Component\Mime\Part\File; use Symfony\Component\Mime\RawMessage; /** @@ -105,7 +105,7 @@ public function testSendInvalidMessage() $message = new Email(); $message->to('recipient@example.org'); $message->from('sender@example.org'); - $message->addPart(new DataPart(new BodyFile('/does_not_exists'))); + $message->addPart(new DataPart(new File('/does_not_exists'))); try { $transport->send($message); diff --git a/src/Symfony/Component/Mime/Email.php b/src/Symfony/Component/Mime/Email.php index 36464fc03e9ea..9a60f42170e86 100644 --- a/src/Symfony/Component/Mime/Email.php +++ b/src/Symfony/Component/Mime/Email.php @@ -13,8 +13,8 @@ use Symfony\Component\Mime\Exception\LogicException; use Symfony\Component\Mime\Part\AbstractPart; -use Symfony\Component\Mime\Part\BodyFile; use Symfony\Component\Mime\Part\DataPart; +use Symfony\Component\Mime\Part\File; use Symfony\Component\Mime\Part\Multipart\AlternativePart; use Symfony\Component\Mime\Part\Multipart\MixedPart; use Symfony\Component\Mime\Part\Multipart\RelatedPart; @@ -335,7 +335,7 @@ public function attach($body, string $name = null, string $contentType = null): */ public function attachFromPath(string $path, string $name = null, string $contentType = null): static { - return $this->addPart(new DataPart(new BodyFile($path), $name, $contentType)); + return $this->addPart(new DataPart(new File($path), $name, $contentType)); } /** @@ -353,7 +353,7 @@ public function embed($body, string $name = null, string $contentType = null): s */ public function embedFromPath(string $path, string $name = null, string $contentType = null): static { - return $this->addPart((new DataPart(new BodyFile($path), $name, $contentType))->asInline()); + return $this->addPart((new DataPart(new File($path), $name, $contentType))->asInline()); } /** diff --git a/src/Symfony/Component/Mime/Part/DataPart.php b/src/Symfony/Component/Mime/Part/DataPart.php index 076f081d7811e..daac6ac789cd4 100644 --- a/src/Symfony/Component/Mime/Part/DataPart.php +++ b/src/Symfony/Component/Mime/Part/DataPart.php @@ -27,18 +27,18 @@ class DataPart extends TextPart private $cid; /** - * @param resource|string|BodyFile $body Use a BodyFile instance to defer loading the file until rendering + * @param resource|string|File $body Use a File instance to defer loading the file until rendering */ public function __construct($body, string $filename = null, string $contentType = null, string $encoding = null) { unset($this->_parent); - if ($body instanceof BodyFile && !$filename) { + if ($body instanceof File && !$filename) { $filename = basename($body->getPath()); } if (null === $contentType) { - $contentType = $body instanceof BodyFile ? $body->getContentType() : 'application/octet-stream'; + $contentType = $body instanceof File ? $body->getContentType() : 'application/octet-stream'; } [$this->mediaType, $subtype] = explode('/', $contentType); @@ -53,7 +53,7 @@ public function __construct($body, string $filename = null, string $contentType public static function fromPath(string $path, string $name = null, string $contentType = null): self { - return new self(new BodyFile($path), $name, $contentType); + return new self(new File($path), $name, $contentType); } /** diff --git a/src/Symfony/Component/Mime/Part/BodyFile.php b/src/Symfony/Component/Mime/Part/File.php similarity index 98% rename from src/Symfony/Component/Mime/Part/BodyFile.php rename to src/Symfony/Component/Mime/Part/File.php index 979026ee1e36c..16269c1bd165a 100644 --- a/src/Symfony/Component/Mime/Part/BodyFile.php +++ b/src/Symfony/Component/Mime/Part/File.php @@ -16,7 +16,7 @@ /** * @author Fabien Potencier */ -class BodyFile +class File { private static $mimeTypes; diff --git a/src/Symfony/Component/Mime/Part/TextPart.php b/src/Symfony/Component/Mime/Part/TextPart.php index 8188ac3610300..66c7807378868 100644 --- a/src/Symfony/Component/Mime/Part/TextPart.php +++ b/src/Symfony/Component/Mime/Part/TextPart.php @@ -40,7 +40,7 @@ class TextPart extends AbstractPart private $seekable; /** - * @param resource|string|BodyFile $body Use a BodyFile instance to defer loading the file until rendering + * @param resource|string|File $body Use a File instance to defer loading the file until rendering */ public function __construct($body, ?string $charset = 'utf-8', string $subtype = 'plain', string $encoding = null) { @@ -48,11 +48,11 @@ public function __construct($body, ?string $charset = 'utf-8', string $subtype = parent::__construct(); - if (!\is_string($body) && !\is_resource($body) && !$body instanceof BodyFile) { - 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))); + if (!\is_string($body) && !\is_resource($body) && !$body instanceof File) { + 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))); } - if ($body instanceof BodyFile) { + if ($body instanceof File) { $path = $body->getPath(); if ((is_file($path) && !is_readable($path)) || is_dir($path)) { throw new InvalidArgumentException(sprintf('Path "%s" is not readable.', $path)); @@ -118,7 +118,7 @@ public function getName(): ?string public function getBody(): string { - if ($this->body instanceof BodyFile) { + if ($this->body instanceof File) { return file_get_contents($this->body->getPath()); } @@ -140,7 +140,7 @@ public function bodyToString(): string public function bodyToIterable(): iterable { - if ($this->body instanceof BodyFile) { + if ($this->body instanceof File) { $path = $this->body->getPath(); if (false === $handle = @fopen($path, 'r', false)) { throw new InvalidArgumentException(sprintf('Unable to open path "%s".', $path)); diff --git a/src/Symfony/Component/Mime/Tests/EmailTest.php b/src/Symfony/Component/Mime/Tests/EmailTest.php index b71fe9e2234cc..f5ffbb7638429 100644 --- a/src/Symfony/Component/Mime/Tests/EmailTest.php +++ b/src/Symfony/Component/Mime/Tests/EmailTest.php @@ -15,8 +15,8 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Mime\Address; use Symfony\Component\Mime\Email; -use Symfony\Component\Mime\Part\BodyFile; use Symfony\Component\Mime\Part\DataPart; +use Symfony\Component\Mime\Part\File; use Symfony\Component\Mime\Part\Multipart\AlternativePart; use Symfony\Component\Mime\Part\Multipart\MixedPart; use Symfony\Component\Mime\Part\Multipart\RelatedPart; @@ -463,8 +463,8 @@ public function testAttachments() $att = DataPart::fromPath($name, 'test'); $inline = DataPart::fromPath($name, 'test')->asInline(); $e = new Email(); - $e->addPart(new DataPart(new BodyFile($name))); - $e->addPart((new DataPart(new BodyFile($name)))->asInline()); + $e->addPart(new DataPart(new File($name))); + $e->addPart((new DataPart(new File($name)))->asInline()); $this->assertEquals([$att->bodyToString(), $inline->bodyToString()], array_map(function (DataPart $a) { return $a->bodyToString(); }, $e->getAttachments())); $this->assertEquals([$att->getPreparedHeaders(), $inline->getPreparedHeaders()], array_map(function (DataPart $a) { return $a->getPreparedHeaders(); }, $e->getAttachments())); } diff --git a/src/Symfony/Component/Mime/Tests/Part/TextPartTest.php b/src/Symfony/Component/Mime/Tests/Part/TextPartTest.php index 9381f6cc77677..905349e670048 100644 --- a/src/Symfony/Component/Mime/Tests/Part/TextPartTest.php +++ b/src/Symfony/Component/Mime/Tests/Part/TextPartTest.php @@ -15,7 +15,7 @@ use Symfony\Component\Mime\Header\Headers; use Symfony\Component\Mime\Header\ParameterizedHeader; use Symfony\Component\Mime\Header\UnstructuredHeader; -use Symfony\Component\Mime\Part\BodyFile; +use Symfony\Component\Mime\Part\File; use Symfony\Component\Mime\Part\TextPart; class TextPartTest extends TestCase @@ -47,9 +47,9 @@ public function testConstructorWithResource() fclose($f); } - public function testConstructorWithBodyFile() + public function testConstructorWithFile() { - $p = new TextPart(new BodyFile(\dirname(__DIR__).'/Fixtures/content.txt')); + $p = new TextPart(new File(\dirname(__DIR__).'/Fixtures/content.txt')); $this->assertSame('content', $p->getBody()); $this->assertSame('content', $p->bodyToString()); $this->assertSame('content', implode('', iterator_to_array($p->bodyToIterable())));