Allow PHP-8.2 and up Compatibility instead of just PHP-8.4

This commit is contained in:
johnnyq
2026-06-12 17:06:10 -04:00
parent 2204bd52f4
commit d3a93652f3
220 changed files with 7198 additions and 2635 deletions

View File

@@ -1,11 +1,6 @@
CHANGELOG
=========
8.0
---
* Replace `__sleep/wakeup()` by `__(un)serialize()` on `AbstractPart` implementations
7.4
---

View File

@@ -65,11 +65,52 @@ abstract class AbstractPart
public function __serialize(): array
{
return ['headers' => $this->headers];
if (!method_exists($this, '__sleep')) {
return ['headers' => $this->headers];
}
trigger_deprecation('symfony/mime', '7.4', 'Implementing "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));
$data = [];
foreach ($this->__sleep() as $key) {
try {
if (($r = new \ReflectionProperty($this, $key))->isInitialized($this)) {
$data[$key] = $r->getValue($this);
}
} catch (\ReflectionException) {
$data[$key] = $this->$key;
}
}
return $data;
}
public function __unserialize(array $data): void
{
$this->headers = $data['headers'];
if ($wakeup = method_exists($this, '__wakeup') && self::class === (new \ReflectionMethod($this, '__unserialize'))->class) {
trigger_deprecation('symfony/mime', '7.4', 'Implementing "%s::__wakeup()" is deprecated, use "__unserialize()" instead.', get_debug_type($this));
}
if (['headers'] === array_keys($data)) {
$this->headers = $data['headers'];
if ($wakeup) {
$this->__wakeup();
}
return;
}
trigger_deprecation('symfony/mime', '7.4', 'Passing more than just key "headers" to "%s::__unserialize()" is deprecated, populate properties in "%s::__unserialize()" instead.', self::class, get_debug_type($this));
\Closure::bind(function ($data) use ($wakeup) {
foreach ($data as $key => $value) {
$this->{("\0" === $key[0] ?? '') ? substr($key, 1 + strrpos($key, "\0")) : $key} = $value;
}
if ($wakeup) {
$this->__wakeup();
}
}, $this, static::class)($data);
}
}

View File

@@ -19,6 +19,9 @@ use Symfony\Component\Mime\Header\Headers;
*/
class DataPart extends TextPart
{
/** @internal, to be removed in 8.0 */
protected array $_parent;
private ?string $filename = null;
private string $mediaType;
private ?string $cid = null;
@@ -128,24 +131,118 @@ class DataPart extends TextPart
public function __serialize(): array
{
$parent = parent::__serialize();
$headers = $parent['_headers'];
unset($parent['_headers']);
if (self::class === (new \ReflectionMethod($this, '__sleep'))->class || self::class !== (new \ReflectionMethod($this, '__serialize'))->class) {
$parent = parent::__serialize();
$headers = $parent['_headers'];
unset($parent['_headers']);
return [
'_headers' => $headers,
'_parent' => $parent,
'filename' => $this->filename,
'mediaType' => $this->mediaType,
'cid' => $this->cid,
];
return [
'_headers' => $headers,
'_parent' => $parent,
'filename' => $this->filename,
'mediaType' => $this->mediaType,
'cid' => $this->cid,
];
}
trigger_deprecation('symfony/mime', '7.4', 'Implementing "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));
$data = [];
foreach ($this->__sleep() as $key) {
try {
if (($r = new \ReflectionProperty($this, $key))->isInitialized($this)) {
$data[$key] = $r->getValue($this);
}
} catch (\ReflectionException) {
$data[$key] = $this->$key;
}
}
return $data;
}
public function __unserialize(array $data): void
{
parent::__unserialize(['_headers' => $data['_headers'] ?? $data["\0*\0_headers"], ...$data['_parent'] ?? $data["\0*\0_parent"]]);
$this->filename = $data['filename'] ?? $data["\0".self::class."\0filename"] ?? null;
$this->mediaType = $data['mediaType'] ?? $data["\0".self::class."\0mediaType"];
$this->cid = $data['cid'] ?? $data["\0".self::class."\0cid"] ?? null;
if ($wakeup = self::class !== (new \ReflectionMethod($this, '__wakeup'))->class && self::class === (new \ReflectionMethod($this, '__unserialize'))->class) {
trigger_deprecation('symfony/mime', '7.4', 'Implementing "%s::__wakeup()" is deprecated, use "__unserialize()" instead.', get_debug_type($this));
}
if (['_headers', '_parent', 'filename', 'mediaType'] === array_keys($data) || ['_headers', '_parent', 'filename', 'mediaType', 'cid'] === array_keys($data)) {
parent::__unserialize(['_headers' => $data['_headers'], ...$data['_parent']]);
$this->filename = $data['filename'];
$this->mediaType = $data['mediaType'];
$this->cid = $data['cid'] ?? null;
if ($wakeup) {
$this->__wakeup();
}
return;
}
if (["\0*\0_headers", "\0*\0_parent", "\0".self::class."\0filename", "\0".self::class."\0mediaType"] === array_keys($data)) {
parent::__unserialize(['_headers' => $data["\0*\0_headers"], ...$data["\0*\0_parent"]]);
$this->filename = $data["\0".self::class."\0filename"];
$this->mediaType = $data["\0".self::class."\0mediaType"];
if ($wakeup) {
$this->__wakeup();
}
return;
}
trigger_deprecation('symfony/mime', '7.4', 'Passing extra keys to "%s::__unserialize()" is deprecated, populate properties in "%s::__unserialize()" instead.', self::class, get_debug_type($this));
\Closure::bind(function ($data) use ($wakeup) {
foreach ($data as $key => $value) {
$this->{("\0" === $key[0] ?? '') ? substr($key, 1 + strrpos($key, "\0")) : $key} = $value;
}
if ($wakeup) {
$this->__wakeup();
}
}, $this, static::class)($data);
}
/**
* @deprecated since Symfony 7.4, will be replaced by `__serialize()` in 8.0
*/
public function __sleep(): array
{
trigger_deprecation('symfony/mime', '7.4', 'Calling "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));
// converts the body to a string
parent::__sleep();
$this->_parent = [];
foreach (['body', 'charset', 'subtype', 'disposition', 'name', 'encoding'] as $name) {
$r = new \ReflectionProperty(TextPart::class, $name);
$this->_parent[$name] = $r->getValue($this);
}
$this->_headers = $this->getHeaders();
return ['_headers', '_parent', 'filename', 'mediaType', 'cid'];
}
/**
* @deprecated since Symfony 7.4, will be replaced by `__unserialize()` in 8.0
*/
public function __wakeup(): void
{
$r = new \ReflectionProperty(AbstractPart::class, 'headers');
$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]) && !$this->_parent[$name] instanceof File) {
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}
$r = new \ReflectionProperty(TextPart::class, $name);
$r->setValue($this, $this->_parent[$name]);
}
unset($this->_parent);
}
}

View File

@@ -18,6 +18,9 @@ use Symfony\Component\Mime\Header\Headers;
*/
class SMimePart extends AbstractPart
{
/** @internal, to be removed in 8.0 */
protected Headers $_headers;
public function __construct(
private iterable|string $body,
private string $type,
@@ -83,18 +86,35 @@ class SMimePart extends AbstractPart
public function __serialize(): array
{
// convert iterables to strings for serialization
if (is_iterable($this->body)) {
$this->body = $this->bodyToString();
if (self::class === (new \ReflectionMethod($this, '__sleep'))->class || self::class !== (new \ReflectionMethod($this, '__serialize'))->class) {
// convert iterables to strings for serialization
if (is_iterable($this->body)) {
$this->body = $this->bodyToString();
}
return [
'_headers' => $this->getHeaders(),
'body' => $this->body,
'type' => $this->type,
'subtype' => $this->subtype,
'parameters' => $this->parameters,
];
}
return [
'_headers' => $this->getHeaders(),
'body' => $this->body,
'type' => $this->type,
'subtype' => $this->subtype,
'parameters' => $this->parameters,
];
trigger_deprecation('symfony/mime', '7.4', 'Implementing "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));
$data = [];
foreach ($this->__sleep() as $key) {
try {
if (($r = new \ReflectionProperty($this, $key))->isInitialized($this)) {
$data[$key] = $r->getValue($this);
}
} catch (\ReflectionException) {
$data[$key] = $this->$key;
}
}
return $data;
}
public function __unserialize(array $data): void
@@ -105,10 +125,81 @@ class SMimePart extends AbstractPart
}
}
parent::__unserialize(['headers' => $data['_headers'] ?? $data["\0*\0_headers"]]);
$this->body = $data['body'] ?? $data["\0".self::class."\0body"];
$this->type = $data['type'] ?? $data["\0".self::class."\0type"];
$this->subtype = $data['subtype'] ?? $data["\0".self::class."\0subtype"];
$this->parameters = $data['parameters'] ?? $data["\0".self::class."\0parameters"];
if ($wakeup = self::class !== (new \ReflectionMethod($this, '__wakeup'))->class && self::class === (new \ReflectionMethod($this, '__unserialize'))->class) {
trigger_deprecation('symfony/mime', '7.4', 'Implementing "%s::__wakeup()" is deprecated, use "__unserialize()" instead.', get_debug_type($this));
}
if (['_headers', 'body', 'type', 'subtype', 'parameters'] === array_keys($data)) {
parent::__unserialize(['headers' => $data['_headers']]);
$this->body = $data['body'];
$this->type = $data['type'];
$this->subtype = $data['subtype'];
$this->parameters = $data['parameters'];
if ($wakeup) {
$this->__wakeup();
}
return;
}
$p = "\0".self::class."\0";
if (["\0*\0_headers", $p.'body', $p.'type', $p.'subtype', $p.'parameters'] === array_keys($data)) {
$r = new \ReflectionProperty(parent::class, 'headers');
$r->setValue($this, $data["\0*\0_headers"]);
$this->body = $data[$p.'body'];
$this->type = $data[$p.'type'];
$this->subtype = $data[$p.'subtype'];
$this->parameters = $data[$p.'parameters'];
if ($wakeup) {
$this->_headers = $data["\0*\0_headers"];
$this->__wakeup();
}
return;
}
trigger_deprecation('symfony/mime', '7.4', 'Passing extra keys to "%s::__unserialize()" is deprecated, populate properties in "%s::__unserialize()" instead.', self::class, get_debug_type($this));
\Closure::bind(function ($data) use ($wakeup) {
foreach ($data as $key => $value) {
$this->{("\0" === $key[0] ?? '') ? substr($key, 1 + strrpos($key, "\0")) : $key} = $value;
}
if ($wakeup) {
$this->__wakeup();
}
}, $this, static::class)($data);
}
/**
* @deprecated since Symfony 7.4, will be replaced by `__serialize()` in 8.0
*/
public function __sleep(): array
{
trigger_deprecation('symfony/mime', '7.4', 'Calling "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));
// 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'];
}
/**
* @deprecated since Symfony 7.4, will be replaced by `__unserialize()` in 8.0
*/
public function __wakeup(): void
{
trigger_deprecation('symfony/mime', '7.4', 'Calling "%s::__wakeup()" is deprecated, use "__unserialize()" instead.', get_debug_type($this));
$r = new \ReflectionProperty(AbstractPart::class, 'headers');
$r->setValue($this, $this->_headers);
unset($this->_headers);
}
}

View File

@@ -25,6 +25,9 @@ class TextPart extends AbstractPart
{
private const DEFAULT_ENCODERS = ['quoted-printable', 'base64', '8bit'];
/** @internal, to be removed in 8.0 */
protected Headers $_headers;
private static array $encoders = [];
/** @var resource|string|File */
@@ -237,21 +240,38 @@ class TextPart extends AbstractPart
public function __serialize(): array
{
// convert resources to strings for serialization
if (null !== $this->seekable) {
$this->body = $this->getBody();
$this->seekable = null;
if (self::class === (new \ReflectionMethod($this, '__sleep'))->class || self::class !== (new \ReflectionMethod($this, '__serialize'))->class) {
// convert resources to strings for serialization
if (null !== $this->seekable) {
$this->body = $this->getBody();
$this->seekable = null;
}
return [
'_headers' => $this->getHeaders(),
'body' => $this->body,
'charset' => $this->charset,
'subtype' => $this->subtype,
'disposition' => $this->disposition,
'name' => $this->name,
'encoding' => $this->encoding,
];
}
return [
'_headers' => $this->getHeaders(),
'body' => $this->body,
'charset' => $this->charset,
'subtype' => $this->subtype,
'disposition' => $this->disposition,
'name' => $this->name,
'encoding' => $this->encoding,
];
trigger_deprecation('symfony/mime', '7.4', 'Implementing "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));
$data = [];
foreach ($this->__sleep() as $key) {
try {
if (($r = new \ReflectionProperty($this, $key))->isInitialized($this)) {
$data[$key] = $r->getValue($this);
}
} catch (\ReflectionException) {
$data[$key] = $this->$key;
}
}
return $data;
}
public function __unserialize(array $data): void
@@ -262,19 +282,91 @@ class TextPart extends AbstractPart
}
}
if ($wakeup = self::class !== (new \ReflectionMethod($this, '__wakeup'))->class && self::class === (new \ReflectionMethod($this, '__unserialize'))->class) {
trigger_deprecation('symfony/mime', '7.4', 'Implementing "%s::__wakeup()" is deprecated, use "__unserialize()" instead.', get_debug_type($this));
}
if ($headers = $data['_headers'] ?? $data["\0*\0_headers"] ?? null) {
unset($data['_headers'], $data["\0*\0_headers"]);
parent::__unserialize(['headers' => $headers]);
}
$this->body = $data['body'] ?? $data["\0".self::class."\0body"];
$this->charset = $data['charset'] ?? $data["\0".self::class."\0charset"] ?? null;
$this->subtype = $data['subtype'] ?? $data["\0".self::class."\0subtype"];
$this->disposition = $data['disposition'] ?? $data["\0".self::class."\0disposition"] ?? null;
$this->name = $data['name'] ?? $data["\0".self::class."\0name"] ?? null;
$this->encoding = $data['encoding'] ?? $data["\0".self::class."\0encoding"];
if (['body', 'charset', 'subtype', 'disposition', 'name', 'encoding'] === array_keys($data)) {
parent::__unserialize(['headers' => $headers]);
$this->body = $data['body'];
$this->charset = $data['charset'];
$this->subtype = $data['subtype'];
$this->disposition = $data['disposition'];
$this->name = $data['name'];
$this->encoding = $data['encoding'];
if (!\is_string($this->body) && !$this->body instanceof File) {
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
if ($wakeup) {
$this->__wakeup();
} elseif (!\is_string($this->body) && !$this->body instanceof File) {
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}
return;
}
if (["\0".self::class."\0body", "\0".self::class."\0charset", "\0".self::class."\0subtype", "\0".self::class."\0disposition", "\0".self::class."\0name", "\0".self::class."\0encoding"] === array_keys($data)) {
$this->body = $data["\0".self::class."\0body"];
$this->charset = $data["\0".self::class."\0charset"];
$this->subtype = $data["\0".self::class."\0subtype"];
$this->disposition = $data["\0".self::class."\0disposition"];
$this->name = $data["\0".self::class."\0name"];
$this->encoding = $data["\0".self::class."\0encoding"];
if ($wakeup) {
$this->_headers = $headers;
$this->__wakeup();
} elseif (!\is_string($this->body) && !$this->body instanceof File) {
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}
return;
}
trigger_deprecation('symfony/mime', '7.4', 'Passing extra keys to "%s::__unserialize()" is deprecated, populate properties in "%s::__unserialize()" instead.', self::class, get_debug_type($this));
\Closure::bind(function ($data) use ($wakeup) {
foreach ($data as $key => $value) {
$this->{("\0" === $key[0] ?? '') ? substr($key, 1 + strrpos($key, "\0")) : $key} = $value;
}
if ($wakeup) {
$this->__wakeup();
}
}, $this, static::class)($data);
}
/**
* @deprecated since Symfony 7.4, will be replaced by `__serialize()` in 8.0
*/
public function __sleep(): array
{
trigger_deprecation('symfony/mime', '7.4', 'Calling "%s::__sleep()" is deprecated, use "__serialize()" instead.', get_debug_type($this));
// convert resources to strings for serialization
if (null !== $this->seekable) {
$this->body = $this->getBody();
$this->seekable = null;
}
$this->_headers = $this->getHeaders();
return ['_headers', 'body', 'charset', 'subtype', 'disposition', 'name', 'encoding'];
}
/**
* @deprecated since Symfony 7.4, will be replaced by `__unserialize()` in 8.0
*/
public function __wakeup(): void
{
trigger_deprecation('symfony/mime', '7.4', 'Calling "%s::__wakeup()" is deprecated, use "__unserialize()" instead.', get_debug_type($this));
$r = new \ReflectionProperty(AbstractPart::class, 'headers');
$r->setValue($this, $this->_headers);
unset($this->_headers);
}
}

View File

@@ -3,13 +3,6 @@ MIME Component
The MIME component allows manipulating MIME messages.
Sponsor
-------
This package is looking for a [backer][1].
Help Symfony by [sponsoring][3] its development!
Resources
---------
@@ -18,6 +11,3 @@ Resources
* [Report issues](https://github.com/symfony/symfony/issues) and
[send Pull Requests](https://github.com/symfony/symfony/pulls)
in the [main Symfony repository](https://github.com/symfony/symfony)
[1]: https://symfony.com/backers
[3]: https://symfony.com/sponsor

View File

@@ -16,7 +16,8 @@
}
],
"require": {
"php": ">=8.4.1",
"php": ">=8.2",
"symfony/deprecation-contracts": "^2.5|^3",
"symfony/polyfill-intl-idn": "^1.10",
"symfony/polyfill-mbstring": "^1.0"
},
@@ -24,16 +25,18 @@
"egulias/email-validator": "^2.1.10|^3.1|^4",
"league/html-to-markdown": "^5.0",
"phpdocumentor/reflection-docblock": "^5.2|^6.0",
"symfony/dependency-injection": "^7.4|^8.0",
"symfony/process": "^7.4|^8.0",
"symfony/property-access": "^7.4|^8.0",
"symfony/property-info": "^7.4|^8.0",
"symfony/serializer": "^7.4|^8.0"
"symfony/dependency-injection": "^6.4|^7.0|^8.0",
"symfony/process": "^6.4|^7.0|^8.0",
"symfony/property-access": "^6.4|^7.0|^8.0",
"symfony/property-info": "^6.4|^7.0|^8.0",
"symfony/serializer": "^6.4.3|^7.0.3|^8.0"
},
"conflict": {
"egulias/email-validator": "~3.0.0",
"phpdocumentor/reflection-docblock": "<5.2|>=7",
"phpdocumentor/type-resolver": "<1.5.1"
"phpdocumentor/type-resolver": "<1.5.1",
"symfony/mailer": "<6.4",
"symfony/serializer": "<6.4.3|>7.0,<7.0.3"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Mime\\": "" },