package and depencies
This commit is contained in:
@@ -90,10 +90,6 @@ abstract class AbstractMultipartPart extends AbstractPart
|
||||
|
||||
private function getBoundary(): string
|
||||
{
|
||||
if (null === $this->boundary) {
|
||||
$this->boundary = strtr(base64_encode(random_bytes(6)), '+/', '-_');
|
||||
}
|
||||
|
||||
return $this->boundary;
|
||||
return $this->boundary ??= strtr(base64_encode(random_bytes(6)), '+/', '-_');
|
||||
}
|
||||
}
|
||||
|
80
vendor/symfony/mime/Part/DataPart.php
vendored
80
vendor/symfony/mime/Part/DataPart.php
vendored
@@ -13,7 +13,6 @@ namespace Symfony\Component\Mime\Part;
|
||||
|
||||
use Symfony\Component\Mime\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Mime\Header\Headers;
|
||||
use Symfony\Component\Mime\MimeTypes;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
@@ -23,23 +22,22 @@ class DataPart extends TextPart
|
||||
/** @internal */
|
||||
protected $_parent;
|
||||
|
||||
private static $mimeTypes;
|
||||
|
||||
private $filename;
|
||||
private $mediaType;
|
||||
private $cid;
|
||||
private $handle;
|
||||
|
||||
/**
|
||||
* @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 $filename = null, string $contentType = null, string $encoding = null)
|
||||
{
|
||||
unset($this->_parent);
|
||||
|
||||
if (null === $contentType) {
|
||||
$contentType = 'application/octet-stream';
|
||||
if ($body instanceof File && !$filename) {
|
||||
$filename = $body->getFilename();
|
||||
}
|
||||
|
||||
$contentType ??= $body instanceof File ? $body->getContentType() : 'application/octet-stream';
|
||||
[$this->mediaType, $subtype] = explode('/', $contentType);
|
||||
|
||||
parent::__construct($body, null, $subtype, $encoding);
|
||||
@@ -53,42 +51,31 @@ class DataPart extends TextPart
|
||||
|
||||
public static function fromPath(string $path, string $name = null, string $contentType = null): self
|
||||
{
|
||||
if (null === $contentType) {
|
||||
$ext = strtolower(substr($path, strrpos($path, '.') + 1));
|
||||
if (null === self::$mimeTypes) {
|
||||
self::$mimeTypes = new MimeTypes();
|
||||
}
|
||||
$contentType = self::$mimeTypes->getMimeTypes($ext)[0] ?? 'application/octet-stream';
|
||||
}
|
||||
|
||||
if ((is_file($path) && !is_readable($path)) || is_dir($path)) {
|
||||
throw new InvalidArgumentException(sprintf('Path "%s" is not readable.', $path));
|
||||
}
|
||||
|
||||
if (false === $handle = @fopen($path, 'r', false)) {
|
||||
throw new InvalidArgumentException(sprintf('Unable to open path "%s".', $path));
|
||||
}
|
||||
|
||||
if (!is_file($path)) {
|
||||
$cache = fopen('php://temp', 'r+');
|
||||
stream_copy_to_stream($handle, $cache);
|
||||
$handle = $cache;
|
||||
}
|
||||
|
||||
$p = new self($handle, $name ?: basename($path), $contentType);
|
||||
$p->handle = $handle;
|
||||
|
||||
return $p;
|
||||
return new self(new File($path), $name, $contentType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function asInline()
|
||||
public function asInline(): static
|
||||
{
|
||||
return $this->setDisposition('inline');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setContentId(string $cid): static
|
||||
{
|
||||
if (!str_contains($cid, '@')) {
|
||||
throw new InvalidArgumentException(sprintf('Invalid cid "%s".', $cid));
|
||||
}
|
||||
|
||||
$this->cid = $cid;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getContentId(): string
|
||||
{
|
||||
return $this->cid ?: $this->cid = $this->generateContentId();
|
||||
@@ -129,22 +116,22 @@ class DataPart extends TextPart
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function getFilename(): ?string
|
||||
{
|
||||
return $this->filename;
|
||||
}
|
||||
|
||||
public function getContentType(): string
|
||||
{
|
||||
return implode('/', [$this->getMediaType(), $this->getMediaSubtype()]);
|
||||
}
|
||||
|
||||
private function generateContentId(): string
|
||||
{
|
||||
return bin2hex(random_bytes(16)).'@symfony';
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
if (null !== $this->handle && \is_resource($this->handle)) {
|
||||
fclose($this->handle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function __sleep()
|
||||
public function __sleep(): array
|
||||
{
|
||||
// converts the body to a string
|
||||
parent::__sleep();
|
||||
@@ -152,7 +139,6 @@ class DataPart extends TextPart
|
||||
$this->_parent = [];
|
||||
foreach (['body', 'charset', 'subtype', 'disposition', 'name', 'encoding'] as $name) {
|
||||
$r = new \ReflectionProperty(TextPart::class, $name);
|
||||
$r->setAccessible(true);
|
||||
$this->_parent[$name] = $r->getValue($this);
|
||||
}
|
||||
$this->_headers = $this->getHeaders();
|
||||
@@ -163,7 +149,6 @@ class DataPart extends TextPart
|
||||
public function __wakeup()
|
||||
{
|
||||
$r = new \ReflectionProperty(AbstractPart::class, 'headers');
|
||||
$r->setAccessible(true);
|
||||
$r->setValue($this, $this->_headers);
|
||||
unset($this->_headers);
|
||||
|
||||
@@ -175,7 +160,6 @@ class DataPart extends TextPart
|
||||
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
|
||||
}
|
||||
$r = new \ReflectionProperty(TextPart::class, $name);
|
||||
$r->setAccessible(true);
|
||||
$r->setValue($this, $this->_parent[$name]);
|
||||
}
|
||||
unset($this->_parent);
|
||||
|
51
vendor/symfony/mime/Part/File.php
vendored
Normal file
51
vendor/symfony/mime/Part/File.php
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Mime\Part;
|
||||
|
||||
use Symfony\Component\Mime\MimeTypes;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class File
|
||||
{
|
||||
private static $mimeTypes;
|
||||
|
||||
public function __construct(
|
||||
private string $path,
|
||||
private ?string $filename = null,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getPath(): string
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
public function getContentType(): string
|
||||
{
|
||||
$ext = strtolower(pathinfo($this->path, \PATHINFO_EXTENSION));
|
||||
self::$mimeTypes ??= new MimeTypes();
|
||||
|
||||
return self::$mimeTypes->getMimeTypes($ext)[0] ?? 'application/octet-stream';
|
||||
}
|
||||
|
||||
public function getSize(): int
|
||||
{
|
||||
return filesize($this->path);
|
||||
}
|
||||
|
||||
public function getFilename(): string
|
||||
{
|
||||
return $this->filename ??= basename($this->getPath());
|
||||
}
|
||||
}
|
5
vendor/symfony/mime/Part/MessagePart.php
vendored
5
vendor/symfony/mime/Part/MessagePart.php
vendored
@@ -60,10 +60,7 @@ class MessagePart extends DataPart
|
||||
return $this->message->toIterable();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function __sleep()
|
||||
public function __sleep(): array
|
||||
{
|
||||
return ['message'];
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ final class FormDataPart extends AbstractMultipartPart
|
||||
|
||||
foreach ($fields as $name => $value) {
|
||||
if (!\is_string($value) && !\is_array($value) && !$value instanceof TextPart) {
|
||||
throw new InvalidArgumentException(sprintf('A form field value can only be a string, an array, or an instance of TextPart ("%s" given).', get_debug_type($value)));
|
||||
throw new InvalidArgumentException(sprintf('The value of the form field "%s" can only be a string, an array, or an instance of TextPart ("%s" given).', $name, get_debug_type($value)));
|
||||
}
|
||||
|
||||
$this->fields[$name] = $value;
|
||||
@@ -83,7 +83,7 @@ final class FormDataPart extends AbstractMultipartPart
|
||||
return $values;
|
||||
}
|
||||
|
||||
private function preparePart(string $name, $value): TextPart
|
||||
private function preparePart(string $name, string|TextPart $value): TextPart
|
||||
{
|
||||
if (\is_string($value)) {
|
||||
return $this->configurePart($name, new TextPart($value, 'utf-8', 'plain', '8bit'));
|
||||
@@ -96,10 +96,7 @@ final class FormDataPart extends AbstractMultipartPart
|
||||
{
|
||||
static $r;
|
||||
|
||||
if (null === $r) {
|
||||
$r = new \ReflectionProperty(TextPart::class, 'encoding');
|
||||
$r->setAccessible(true);
|
||||
}
|
||||
$r ??= new \ReflectionProperty(TextPart::class, 'encoding');
|
||||
|
||||
$part->setDisposition('form-data');
|
||||
$part->setName($name);
|
||||
|
10
vendor/symfony/mime/Part/SMimePart.php
vendored
10
vendor/symfony/mime/Part/SMimePart.php
vendored
@@ -26,19 +26,12 @@ class SMimePart extends AbstractPart
|
||||
private $subtype;
|
||||
private $parameters;
|
||||
|
||||
/**
|
||||
* @param iterable|string $body
|
||||
*/
|
||||
public function __construct($body, string $type, string $subtype, array $parameters)
|
||||
public function __construct(iterable|string $body, string $type, string $subtype, array $parameters)
|
||||
{
|
||||
unset($this->_headers);
|
||||
|
||||
parent::__construct();
|
||||
|
||||
if (!\is_string($body) && !is_iterable($body)) {
|
||||
throw new \TypeError(sprintf('The body of "%s" must be a string or a iterable (got "%s").', self::class, get_debug_type($body)));
|
||||
}
|
||||
|
||||
$this->body = $body;
|
||||
$this->type = $type;
|
||||
$this->subtype = $subtype;
|
||||
@@ -114,7 +107,6 @@ class SMimePart extends AbstractPart
|
||||
public function __wakeup(): void
|
||||
{
|
||||
$r = new \ReflectionProperty(AbstractPart::class, 'headers');
|
||||
$r->setAccessible(true);
|
||||
$r->setValue($this, $this->_headers);
|
||||
unset($this->_headers);
|
||||
}
|
||||
|
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