package and depencies
This commit is contained in:
52
vendor/symfony/mime/Part/TextPart.php
vendored
52
vendor/symfony/mime/Part/TextPart.php
vendored
@@ -40,7 +40,7 @@ class TextPart extends AbstractPart
|
||||
private $seekable;
|
||||
|
||||
/**
|
||||
* @param resource|string $body
|
||||
* @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,8 +48,15 @@ class TextPart extends AbstractPart
|
||||
|
||||
parent::__construct();
|
||||
|
||||
if (!\is_string($body) && !\is_resource($body)) {
|
||||
throw new \TypeError(sprintf('The body of "%s" must be a string or a resource (got "%s").', self::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 File) {
|
||||
$path = $body->getPath();
|
||||
if ((is_file($path) && !is_readable($path)) || is_dir($path)) {
|
||||
throw new InvalidArgumentException(sprintf('Path "%s" is not readable.', $path));
|
||||
}
|
||||
}
|
||||
|
||||
$this->body = $body;
|
||||
@@ -82,7 +89,7 @@ class TextPart extends AbstractPart
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDisposition(string $disposition)
|
||||
public function setDisposition(string $disposition): static
|
||||
{
|
||||
$this->disposition = $disposition;
|
||||
|
||||
@@ -94,15 +101,27 @@ class TextPart extends AbstractPart
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setName(string $name)
|
||||
public function setName(string $name): static
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the file.
|
||||
*/
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getBody(): string
|
||||
{
|
||||
if ($this->body instanceof File) {
|
||||
return file_get_contents($this->body->getPath());
|
||||
}
|
||||
|
||||
if (null === $this->seekable) {
|
||||
return $this->body;
|
||||
}
|
||||
@@ -121,7 +140,14 @@ class TextPart extends AbstractPart
|
||||
|
||||
public function bodyToIterable(): iterable
|
||||
{
|
||||
if (null !== $this->seekable) {
|
||||
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));
|
||||
}
|
||||
|
||||
yield from $this->getEncoder()->encodeByteStream($handle);
|
||||
} elseif (null !== $this->seekable) {
|
||||
if ($this->seekable) {
|
||||
rewind($this->body);
|
||||
}
|
||||
@@ -170,14 +196,14 @@ class TextPart extends AbstractPart
|
||||
private function getEncoder(): ContentEncoderInterface
|
||||
{
|
||||
if ('8bit' === $this->encoding) {
|
||||
return self::$encoders[$this->encoding] ?? (self::$encoders[$this->encoding] = new EightBitContentEncoder());
|
||||
return self::$encoders[$this->encoding] ??= new EightBitContentEncoder();
|
||||
}
|
||||
|
||||
if ('quoted-printable' === $this->encoding) {
|
||||
return self::$encoders[$this->encoding] ?? (self::$encoders[$this->encoding] = new QpContentEncoder());
|
||||
return self::$encoders[$this->encoding] ??= new QpContentEncoder();
|
||||
}
|
||||
|
||||
return self::$encoders[$this->encoding] ?? (self::$encoders[$this->encoding] = new Base64ContentEncoder());
|
||||
return self::$encoders[$this->encoding] ??= new Base64ContentEncoder();
|
||||
}
|
||||
|
||||
private function chooseEncoding(): string
|
||||
@@ -189,13 +215,10 @@ class TextPart extends AbstractPart
|
||||
return 'quoted-printable';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function __sleep()
|
||||
public function __sleep(): array
|
||||
{
|
||||
// convert resources to strings for serialization
|
||||
if (null !== $this->seekable) {
|
||||
if (null !== $this->seekable || $this->body instanceof File) {
|
||||
$this->body = $this->getBody();
|
||||
$this->seekable = null;
|
||||
}
|
||||
@@ -208,7 +231,6 @@ class TextPart extends AbstractPart
|
||||
public function __wakeup()
|
||||
{
|
||||
$r = new \ReflectionProperty(AbstractPart::class, 'headers');
|
||||
$r->setAccessible(true);
|
||||
$r->setValue($this, $this->_headers);
|
||||
unset($this->_headers);
|
||||
}
|
||||
|
Reference in New Issue
Block a user