mirror of
https://github.com/linuxserver/Heimdall.git
synced 2025-12-03 05:29:53 +09:00
Update to laravel 7
This commit is contained in:
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]);
|
||||
|
||||
Reference in New Issue
Block a user