mirror of
https://github.com/linuxserver/Heimdall.git
synced 2025-12-06 15:04:01 +09:00
Update to laravel 7
This commit is contained in:
@@ -15,8 +15,6 @@ use Symfony\Component\Mime\Header\Headers;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @experimental in 4.3
|
||||
*/
|
||||
abstract class AbstractMultipartPart extends AbstractPart
|
||||
{
|
||||
@@ -76,10 +74,24 @@ abstract class AbstractMultipartPart extends AbstractPart
|
||||
yield '--'.$this->getBoundary()."--\r\n";
|
||||
}
|
||||
|
||||
public function asDebugString(): string
|
||||
{
|
||||
$str = parent::asDebugString();
|
||||
foreach ($this->getParts() as $part) {
|
||||
$lines = explode("\n", $part->asDebugString());
|
||||
$str .= "\n └ ".array_shift($lines);
|
||||
foreach ($lines as $line) {
|
||||
$str .= "\n |".$line;
|
||||
}
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
private function getBoundary(): string
|
||||
{
|
||||
if (null === $this->boundary) {
|
||||
$this->boundary = '_=_symfony_'.time().'_'.bin2hex(random_bytes(16)).'_=_';
|
||||
$this->boundary = strtr(base64_encode(random_bytes(6)), '+/', '-_');
|
||||
}
|
||||
|
||||
return $this->boundary;
|
||||
|
||||
7
vendor/symfony/mime/Part/AbstractPart.php
vendored
7
vendor/symfony/mime/Part/AbstractPart.php
vendored
@@ -15,8 +15,6 @@ use Symfony\Component\Mime\Header\Headers;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @experimental in 4.3
|
||||
*/
|
||||
abstract class AbstractPart
|
||||
{
|
||||
@@ -52,6 +50,11 @@ abstract class AbstractPart
|
||||
yield from $this->bodyToIterable();
|
||||
}
|
||||
|
||||
public function asDebugString(): string
|
||||
{
|
||||
return $this->getMediaType().'/'.$this->getMediaSubtype();
|
||||
}
|
||||
|
||||
abstract public function bodyToString(): string;
|
||||
|
||||
abstract public function bodyToIterable(): iterable;
|
||||
|
||||
42
vendor/symfony/mime/Part/DataPart.php
vendored
42
vendor/symfony/mime/Part/DataPart.php
vendored
@@ -17,11 +17,12 @@ use Symfony\Component\Mime\MimeTypes;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @experimental in 4.3
|
||||
*/
|
||||
class DataPart extends TextPart
|
||||
{
|
||||
/** @internal */
|
||||
protected $_parent;
|
||||
|
||||
private static $mimeTypes;
|
||||
|
||||
private $filename;
|
||||
@@ -34,22 +35,24 @@ class DataPart extends TextPart
|
||||
*/
|
||||
public function __construct($body, string $filename = null, string $contentType = null, string $encoding = null)
|
||||
{
|
||||
unset($this->_parent);
|
||||
|
||||
if (null === $contentType) {
|
||||
$contentType = 'application/octet-stream';
|
||||
}
|
||||
list($this->mediaType, $subtype) = explode('/', $contentType);
|
||||
[$this->mediaType, $subtype] = explode('/', $contentType);
|
||||
|
||||
parent::__construct($body, null, $subtype, $encoding);
|
||||
|
||||
$this->filename = $filename;
|
||||
$this->setName($filename);
|
||||
if (null !== $filename) {
|
||||
$this->filename = $filename;
|
||||
$this->setName($filename);
|
||||
}
|
||||
$this->setDisposition('attachment');
|
||||
}
|
||||
|
||||
public static function fromPath(string $path, string $name = null, string $contentType = null): self
|
||||
{
|
||||
// FIXME: if file is not readable, exception?
|
||||
|
||||
if (null === $contentType) {
|
||||
$ext = strtolower(substr($path, strrpos($path, '.') + 1));
|
||||
if (null === self::$mimeTypes) {
|
||||
@@ -58,8 +61,12 @@ class DataPart extends TextPart
|
||||
$contentType = self::$mimeTypes->getMimeTypes($ext)[0] ?? 'application/octet-stream';
|
||||
}
|
||||
|
||||
if (false === is_readable($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));
|
||||
throw new InvalidArgumentException(sprintf('Unable to open path "%s".', $path));
|
||||
}
|
||||
$p = new self($handle, $name ?: basename($path), $contentType);
|
||||
$p->handle = $handle;
|
||||
@@ -105,6 +112,16 @@ class DataPart extends TextPart
|
||||
return $headers;
|
||||
}
|
||||
|
||||
public function asDebugString(): string
|
||||
{
|
||||
$str = parent::asDebugString();
|
||||
if (null !== $this->filename) {
|
||||
$str .= ' filename: '.$this->filename;
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
private function generateContentId(): string
|
||||
{
|
||||
return bin2hex(random_bytes(16)).'@symfony';
|
||||
@@ -117,6 +134,9 @@ class DataPart extends TextPart
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function __sleep()
|
||||
{
|
||||
// converts the body to a string
|
||||
@@ -140,7 +160,13 @@ class DataPart extends TextPart
|
||||
$r->setValue($this, $this->_headers);
|
||||
unset($this->_headers);
|
||||
|
||||
if (!\is_array($this->_parent)) {
|
||||
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
|
||||
}
|
||||
foreach (['body', 'charset', 'subtype', 'disposition', 'name', 'encoding'] as $name) {
|
||||
if (null !== $this->_parent[$name] && !\is_string($this->_parent[$name])) {
|
||||
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
|
||||
}
|
||||
$r = new \ReflectionProperty(TextPart::class, $name);
|
||||
$r->setAccessible(true);
|
||||
$r->setValue($this, $this->_parent[$name]);
|
||||
|
||||
2
vendor/symfony/mime/Part/MessagePart.php
vendored
2
vendor/symfony/mime/Part/MessagePart.php
vendored
@@ -18,8 +18,6 @@ use Symfony\Component\Mime\RawMessage;
|
||||
* @final
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @experimental in 4.3
|
||||
*/
|
||||
class MessagePart extends DataPart
|
||||
{
|
||||
|
||||
@@ -15,8 +15,6 @@ use Symfony\Component\Mime\Part\AbstractMultipartPart;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @experimental in 4.3
|
||||
*/
|
||||
final class AlternativePart extends AbstractMultipartPart
|
||||
{
|
||||
|
||||
@@ -16,8 +16,6 @@ use Symfony\Component\Mime\Part\MessagePart;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @experimental in 4.3
|
||||
*/
|
||||
final class DigestPart extends AbstractMultipartPart
|
||||
{
|
||||
|
||||
@@ -20,15 +20,13 @@ 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
|
||||
* @param array<string|array|DataPart> $fields
|
||||
*/
|
||||
public function __construct(array $fields = [])
|
||||
{
|
||||
@@ -36,13 +34,13 @@ 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).', \is_object($value) ? \get_class($value) : \gettype($value)));
|
||||
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)));
|
||||
}
|
||||
|
||||
$this->fields[$name] = $value;
|
||||
}
|
||||
// HTTP does not support \r\n in header values
|
||||
$this->getHeaders()->setMaxLineLength(PHP_INT_MAX);
|
||||
$this->getHeaders()->setMaxLineLength(\PHP_INT_MAX);
|
||||
}
|
||||
|
||||
public function getMediaSubtype(): string
|
||||
@@ -58,16 +56,34 @@ final class FormDataPart extends AbstractMultipartPart
|
||||
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);
|
||||
|
||||
$prepare = function ($item, $key, $root = null) use (&$values, &$prepare) {
|
||||
if (\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)));
|
||||
}
|
||||
|
||||
$key = key($item);
|
||||
$item = $item[$key];
|
||||
}
|
||||
});
|
||||
|
||||
$fieldName = null !== $root ? sprintf('%s[%s]', $root, $key) : $key;
|
||||
|
||||
if (\is_array($item)) {
|
||||
array_walk($item, $prepare, $fieldName);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$values[] = $this->preparePart($fieldName, $item);
|
||||
};
|
||||
|
||||
array_walk($fields, $prepare);
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
private function preparePart($name, $value): TextPart
|
||||
private function preparePart(string $name, $value): TextPart
|
||||
{
|
||||
if (\is_string($value)) {
|
||||
return $this->configurePart($name, new TextPart($value, 'utf-8', 'plain', '8bit'));
|
||||
@@ -88,7 +104,7 @@ final class FormDataPart extends AbstractMultipartPart
|
||||
$part->setDisposition('form-data');
|
||||
$part->setName($name);
|
||||
// HTTP does not support \r\n in header values
|
||||
$part->getHeaders()->setMaxLineLength(PHP_INT_MAX);
|
||||
$part->getHeaders()->setMaxLineLength(\PHP_INT_MAX);
|
||||
$r->setValue($part, '8bit');
|
||||
|
||||
return $part;
|
||||
|
||||
@@ -15,8 +15,6 @@ use Symfony\Component\Mime\Part\AbstractMultipartPart;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @experimental in 4.3
|
||||
*/
|
||||
final class MixedPart extends AbstractMultipartPart
|
||||
{
|
||||
|
||||
@@ -16,8 +16,6 @@ use Symfony\Component\Mime\Part\AbstractPart;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @experimental in 4.3
|
||||
*/
|
||||
final class RelatedPart extends AbstractMultipartPart
|
||||
{
|
||||
|
||||
121
vendor/symfony/mime/Part/SMimePart.php
vendored
Normal file
121
vendor/symfony/mime/Part/SMimePart.php
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
<?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\Header\Headers;
|
||||
|
||||
/**
|
||||
* @author Sebastiaan Stok <s.stok@rollerscapes.net>
|
||||
*/
|
||||
class SMimePart extends AbstractPart
|
||||
{
|
||||
/** @internal */
|
||||
protected $_headers;
|
||||
|
||||
private $body;
|
||||
private $type;
|
||||
private $subtype;
|
||||
private $parameters;
|
||||
|
||||
/**
|
||||
* @param iterable|string $body
|
||||
*/
|
||||
public function __construct($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;
|
||||
$this->parameters = $parameters;
|
||||
}
|
||||
|
||||
public function getMediaType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function getMediaSubtype(): string
|
||||
{
|
||||
return $this->subtype;
|
||||
}
|
||||
|
||||
public function bodyToString(): string
|
||||
{
|
||||
if (\is_string($this->body)) {
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
$body = '';
|
||||
foreach ($this->body as $chunk) {
|
||||
$body .= $chunk;
|
||||
}
|
||||
$this->body = $body;
|
||||
|
||||
return $body;
|
||||
}
|
||||
|
||||
public function bodyToIterable(): iterable
|
||||
{
|
||||
if (\is_string($this->body)) {
|
||||
yield $this->body;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$body = '';
|
||||
foreach ($this->body as $chunk) {
|
||||
$body .= $chunk;
|
||||
yield $chunk;
|
||||
}
|
||||
$this->body = $body;
|
||||
}
|
||||
|
||||
public function getPreparedHeaders(): Headers
|
||||
{
|
||||
$headers = clone parent::getHeaders();
|
||||
|
||||
$headers->setHeaderBody('Parameterized', 'Content-Type', $this->getMediaType().'/'.$this->getMediaSubtype());
|
||||
|
||||
foreach ($this->parameters as $name => $value) {
|
||||
$headers->setHeaderParameter('Content-Type', $name, $value);
|
||||
}
|
||||
|
||||
return $headers;
|
||||
}
|
||||
|
||||
public function __sleep(): array
|
||||
{
|
||||
// convert iterables to strings for serialization
|
||||
if (is_iterable($this->body)) {
|
||||
$this->body = $this->bodyToString();
|
||||
}
|
||||
|
||||
$this->_headers = $this->getHeaders();
|
||||
|
||||
return ['_headers', 'body', 'type', 'subtype', 'parameters'];
|
||||
}
|
||||
|
||||
public function __wakeup(): void
|
||||
{
|
||||
$r = new \ReflectionProperty(AbstractPart::class, 'headers');
|
||||
$r->setAccessible(true);
|
||||
$r->setValue($this, $this->_headers);
|
||||
unset($this->_headers);
|
||||
}
|
||||
}
|
||||
46
vendor/symfony/mime/Part/TextPart.php
vendored
46
vendor/symfony/mime/Part/TextPart.php
vendored
@@ -20,34 +20,42 @@ use Symfony\Component\Mime\Header\Headers;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @experimental in 4.3
|
||||
*/
|
||||
class TextPart extends AbstractPart
|
||||
{
|
||||
/** @internal */
|
||||
protected $_headers;
|
||||
|
||||
private static $encoders = [];
|
||||
|
||||
private $body;
|
||||
private $charset;
|
||||
private $subtype;
|
||||
/**
|
||||
* @var ?string
|
||||
*/
|
||||
private $disposition;
|
||||
private $name;
|
||||
private $encoding;
|
||||
private $seekable;
|
||||
|
||||
/**
|
||||
* @param resource|string $body
|
||||
*/
|
||||
public function __construct($body, ?string $charset = 'utf-8', $subtype = 'plain', string $encoding = null)
|
||||
public function __construct($body, ?string $charset = 'utf-8', string $subtype = 'plain', string $encoding = null)
|
||||
{
|
||||
unset($this->_headers);
|
||||
|
||||
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, \is_object($body) ? \get_class($body) : \gettype($body)));
|
||||
throw new \TypeError(sprintf('The body of "%s" must be a string or a resource (got "%s").', self::class, get_debug_type($body)));
|
||||
}
|
||||
|
||||
$this->body = $body;
|
||||
$this->charset = $charset;
|
||||
$this->subtype = $subtype;
|
||||
$this->seekable = \is_resource($body) ? stream_get_meta_data($body)['seekable'] && 0 === fseek($body, 0, \SEEK_CUR) : null;
|
||||
|
||||
if (null === $encoding) {
|
||||
$this->encoding = $this->chooseEncoding();
|
||||
@@ -86,7 +94,7 @@ class TextPart extends AbstractPart
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($name)
|
||||
public function setName(string $name)
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
@@ -95,11 +103,11 @@ class TextPart extends AbstractPart
|
||||
|
||||
public function getBody(): string
|
||||
{
|
||||
if (!\is_resource($this->body)) {
|
||||
if (null === $this->seekable) {
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
if (stream_get_meta_data($this->body)['seekable'] ?? false) {
|
||||
if ($this->seekable) {
|
||||
rewind($this->body);
|
||||
}
|
||||
|
||||
@@ -113,8 +121,8 @@ class TextPart extends AbstractPart
|
||||
|
||||
public function bodyToIterable(): iterable
|
||||
{
|
||||
if (\is_resource($this->body)) {
|
||||
if (stream_get_meta_data($this->body)['seekable'] ?? false) {
|
||||
if (null !== $this->seekable) {
|
||||
if ($this->seekable) {
|
||||
rewind($this->body);
|
||||
}
|
||||
yield from $this->getEncoder()->encodeByteStream($this->body);
|
||||
@@ -131,7 +139,7 @@ class TextPart extends AbstractPart
|
||||
if ($this->charset) {
|
||||
$headers->setHeaderParameter('Content-Type', 'charset', $this->charset);
|
||||
}
|
||||
if ($this->name) {
|
||||
if ($this->name && 'form-data' !== $this->disposition) {
|
||||
$headers->setHeaderParameter('Content-Type', 'name', $this->name);
|
||||
}
|
||||
$headers->setHeaderBody('Text', 'Content-Transfer-Encoding', $this->encoding);
|
||||
@@ -146,6 +154,19 @@ class TextPart extends AbstractPart
|
||||
return $headers;
|
||||
}
|
||||
|
||||
public function asDebugString(): string
|
||||
{
|
||||
$str = parent::asDebugString();
|
||||
if (null !== $this->charset) {
|
||||
$str .= ' charset: '.$this->charset;
|
||||
}
|
||||
if (null !== $this->disposition) {
|
||||
$str .= ' disposition: '.$this->disposition;
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
private function getEncoder(): ContentEncoderInterface
|
||||
{
|
||||
if ('8bit' === $this->encoding) {
|
||||
@@ -168,10 +189,13 @@ class TextPart extends AbstractPart
|
||||
return 'quoted-printable';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function __sleep()
|
||||
{
|
||||
// convert resources to strings for serialization
|
||||
if (\is_resource($this->body)) {
|
||||
if (null !== $this->seekable) {
|
||||
$this->body = $this->getBody();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user