提交代码
This commit is contained in:
27
vendor/symfony/mime/Part/Multipart/AlternativePart.php
vendored
Normal file
27
vendor/symfony/mime/Part/Multipart/AlternativePart.php
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
<?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\Multipart;
|
||||
|
||||
use Symfony\Component\Mime\Part\AbstractMultipartPart;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @experimental in 4.3
|
||||
*/
|
||||
final class AlternativePart extends AbstractMultipartPart
|
||||
{
|
||||
public function getMediaSubtype(): string
|
||||
{
|
||||
return 'alternative';
|
||||
}
|
||||
}
|
||||
33
vendor/symfony/mime/Part/Multipart/DigestPart.php
vendored
Normal file
33
vendor/symfony/mime/Part/Multipart/DigestPart.php
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
<?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\Multipart;
|
||||
|
||||
use Symfony\Component\Mime\Part\AbstractMultipartPart;
|
||||
use Symfony\Component\Mime\Part\MessagePart;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @experimental in 4.3
|
||||
*/
|
||||
final class DigestPart extends AbstractMultipartPart
|
||||
{
|
||||
public function __construct(MessagePart ...$parts)
|
||||
{
|
||||
parent::__construct(...$parts);
|
||||
}
|
||||
|
||||
public function getMediaSubtype(): string
|
||||
{
|
||||
return 'digest';
|
||||
}
|
||||
}
|
||||
96
vendor/symfony/mime/Part/Multipart/FormDataPart.php
vendored
Normal file
96
vendor/symfony/mime/Part/Multipart/FormDataPart.php
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
<?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\Multipart;
|
||||
|
||||
use Symfony\Component\Mime\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Mime\Part\AbstractMultipartPart;
|
||||
use Symfony\Component\Mime\Part\DataPart;
|
||||
use Symfony\Component\Mime\Part\TextPart;
|
||||
|
||||
/**
|
||||
* Implements RFC 7578.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @experimental in 4.3
|
||||
*/
|
||||
final class FormDataPart extends AbstractMultipartPart
|
||||
{
|
||||
private $fields = [];
|
||||
|
||||
/**
|
||||
* @param (string|array|DataPart)[] $fields
|
||||
*/
|
||||
public function __construct(array $fields = [])
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
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).', \is_object($value) ? \get_class($value) : \gettype($value)));
|
||||
}
|
||||
|
||||
$this->fields[$name] = $value;
|
||||
}
|
||||
// HTTP does not support \r\n in header values
|
||||
$this->getHeaders()->setMaxLineLength(PHP_INT_MAX);
|
||||
}
|
||||
|
||||
public function getMediaSubtype(): string
|
||||
{
|
||||
return 'form-data';
|
||||
}
|
||||
|
||||
public function getParts(): array
|
||||
{
|
||||
return $this->prepareFields($this->fields);
|
||||
}
|
||||
|
||||
private function prepareFields(array $fields): array
|
||||
{
|
||||
$values = [];
|
||||
array_walk_recursive($fields, function ($item, $key) use (&$values) {
|
||||
if (!\is_array($item)) {
|
||||
$values[] = $this->preparePart($key, $item);
|
||||
}
|
||||
});
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
private function preparePart($name, $value): TextPart
|
||||
{
|
||||
if (\is_string($value)) {
|
||||
return $this->configurePart($name, new TextPart($value, 'utf-8', 'plain', '8bit'));
|
||||
}
|
||||
|
||||
return $this->configurePart($name, $value);
|
||||
}
|
||||
|
||||
private function configurePart(string $name, TextPart $part): TextPart
|
||||
{
|
||||
static $r;
|
||||
|
||||
if (null === $r) {
|
||||
$r = new \ReflectionProperty(TextPart::class, 'encoding');
|
||||
$r->setAccessible(true);
|
||||
}
|
||||
|
||||
$part->setDisposition('form-data');
|
||||
$part->setName($name);
|
||||
// HTTP does not support \r\n in header values
|
||||
$part->getHeaders()->setMaxLineLength(PHP_INT_MAX);
|
||||
$r->setValue($part, '8bit');
|
||||
|
||||
return $part;
|
||||
}
|
||||
}
|
||||
27
vendor/symfony/mime/Part/Multipart/MixedPart.php
vendored
Normal file
27
vendor/symfony/mime/Part/Multipart/MixedPart.php
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
<?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\Multipart;
|
||||
|
||||
use Symfony\Component\Mime\Part\AbstractMultipartPart;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @experimental in 4.3
|
||||
*/
|
||||
final class MixedPart extends AbstractMultipartPart
|
||||
{
|
||||
public function getMediaSubtype(): string
|
||||
{
|
||||
return 'mixed';
|
||||
}
|
||||
}
|
||||
57
vendor/symfony/mime/Part/Multipart/RelatedPart.php
vendored
Normal file
57
vendor/symfony/mime/Part/Multipart/RelatedPart.php
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
<?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\Multipart;
|
||||
|
||||
use Symfony\Component\Mime\Part\AbstractMultipartPart;
|
||||
use Symfony\Component\Mime\Part\AbstractPart;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @experimental in 4.3
|
||||
*/
|
||||
final class RelatedPart extends AbstractMultipartPart
|
||||
{
|
||||
private $mainPart;
|
||||
|
||||
public function __construct(AbstractPart $mainPart, AbstractPart $part, AbstractPart ...$parts)
|
||||
{
|
||||
$this->mainPart = $mainPart;
|
||||
$this->prepareParts($part, ...$parts);
|
||||
|
||||
parent::__construct($part, ...$parts);
|
||||
}
|
||||
|
||||
public function getParts(): array
|
||||
{
|
||||
return array_merge([$this->mainPart], parent::getParts());
|
||||
}
|
||||
|
||||
public function getMediaSubtype(): string
|
||||
{
|
||||
return 'related';
|
||||
}
|
||||
|
||||
private function generateContentId(): string
|
||||
{
|
||||
return bin2hex(random_bytes(16)).'@symfony';
|
||||
}
|
||||
|
||||
private function prepareParts(AbstractPart ...$parts): void
|
||||
{
|
||||
foreach ($parts as $part) {
|
||||
if (!$part->getHeaders()->has('Content-ID')) {
|
||||
$part->getHeaders()->setHeaderBody('Id', 'Content-ID', $this->generateContentId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user