update patch 1

This commit is contained in:
fiqhpratama
2024-12-02 01:18:34 +07:00
parent 453d9bb470
commit 25026b0a85
3380 changed files with 103529 additions and 363623 deletions
+1 -1
View File
@@ -66,7 +66,7 @@ class DataPart extends TextPart
public function setContentId(string $cid): static
{
if (!str_contains($cid, '@')) {
throw new InvalidArgumentException(sprintf('Invalid cid "%s".', $cid));
throw new InvalidArgumentException(\sprintf('The "%s" CID is invalid as it doesn\'t contain an "@".', $cid));
}
$this->cid = $cid;
+3 -3
View File
@@ -52,14 +52,14 @@ final class FormDataPart extends AbstractMultipartPart
$prepare = function ($item, $key, $root = null) use (&$values, &$prepare) {
if (null === $root && \is_int($key) && \is_array($item)) {
if (1 !== \count($item)) {
throw new InvalidArgumentException(sprintf('Form field values with integer keys can only have one array element, the key being the field name and the value being the field value, %d provided.', \count($item)));
throw new InvalidArgumentException(\sprintf('Form field values with integer keys can only have one array element, the key being the field name and the value being the field value, %d provided.', \count($item)));
}
$key = key($item);
$item = $item[$key];
}
$fieldName = null !== $root ? sprintf('%s[%s]', $root, $key) : $key;
$fieldName = null !== $root ? \sprintf('%s[%s]', $root, $key) : $key;
if (\is_array($item)) {
array_walk($item, $prepare, $fieldName);
@@ -68,7 +68,7 @@ final class FormDataPart extends AbstractMultipartPart
}
if (!\is_string($item) && !$item instanceof TextPart) {
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.', $fieldName, get_debug_type($item)));
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.', $fieldName, get_debug_type($item)));
}
$values[] = $this->preparePart($fieldName, $item);
+21 -6
View File
@@ -23,6 +23,8 @@ use Symfony\Component\Mime\Header\Headers;
*/
class TextPart extends AbstractPart
{
private const DEFAULT_ENCODERS = ['quoted-printable', 'base64', '8bit'];
/** @internal */
protected Headers $_headers;
@@ -45,13 +47,13 @@ class TextPart extends AbstractPart
parent::__construct();
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)));
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));
throw new InvalidArgumentException(\sprintf('Path "%s" is not readable.', $path));
}
}
@@ -63,8 +65,8 @@ class TextPart extends AbstractPart
if (null === $encoding) {
$this->encoding = $this->chooseEncoding();
} else {
if ('quoted-printable' !== $encoding && 'base64' !== $encoding && '8bit' !== $encoding) {
throw new InvalidArgumentException(sprintf('The encoding must be one of "quoted-printable", "base64", or "8bit" ("%s" given).', $encoding));
if (!\in_array($encoding, self::DEFAULT_ENCODERS, true) && !\array_key_exists($encoding, self::$encoders)) {
throw new InvalidArgumentException(\sprintf('The encoding must be one of "%s" ("%s" given).', implode('", "', array_unique(array_merge(self::DEFAULT_ENCODERS, array_keys(self::$encoders)))), $encoding));
}
$this->encoding = $encoding;
}
@@ -151,7 +153,7 @@ class TextPart extends AbstractPart
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));
throw new InvalidArgumentException(\sprintf('Unable to open path "%s".', $path));
}
yield from $this->getEncoder()->encodeByteStream($handle);
@@ -211,7 +213,20 @@ class TextPart extends AbstractPart
return self::$encoders[$this->encoding] ??= new QpContentEncoder();
}
return self::$encoders[$this->encoding] ??= new Base64ContentEncoder();
if ('base64' === $this->encoding) {
return self::$encoders[$this->encoding] ??= new Base64ContentEncoder();
}
return self::$encoders[$this->encoding];
}
public static function addEncoder(ContentEncoderInterface $encoder): void
{
if (\in_array($encoder->getName(), self::DEFAULT_ENCODERS, true)) {
throw new InvalidArgumentException('You are not allowed to change the default encoders ("quoted-printable", "base64", and "8bit").');
}
self::$encoders[$encoder->getName()] = $encoder;
}
private function chooseEncoding(): string