Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Mime] Replace __sleep() and __wakeup() with __serialize() and __unserialize() in some Part #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 6.4
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions 7 UPGRADE-6.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ Messenger

* Deprecate `StopWorkerOnSignalsListener` in favor of using the `SignalableCommandInterface`

Mime
----

* Deprecate `DataPart::__sleep()`, `DataPart::__wakeup()`, `MessagePart::__sleep()`,
`MessagePart::__wakeup()`, `SMimePart::__sleep()`, `SMimePart::__wakeup()`,
`TextPart::__sleep()` and `TextPart::__wakeup()`

MonologBridge
-------------

Expand Down
6 changes: 6 additions & 0 deletions 6 src/Symfony/Component/Mime/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
CHANGELOG
=========

6.4

* Deprecate `DataPart::__sleep()`, `DataPart::__wakeup()`, `MessagePart::__sleep()`,
`MessagePart::__wakeup()`, `SMimePart::__sleep()`, `SMimePart::__wakeup()`,
`TextPart::__sleep()` and `TextPart::__wakeup()`

6.3
---

Expand Down
12 changes: 12 additions & 0 deletions 12 src/Symfony/Component/Mime/Part/AbstractMultipartPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ public function asDebugString(): string
return $str;
}

public function __serialize(): array
{
return [...parent::__serialize(), 'boundary' => $this->boundary, 'parts' => $this->parts];
}

public function __unserialize(array $data): void
{
parent::__unserialize($data);
$this->boundary = \array_key_exists('boundary', $data) ? $data['boundary'] : $data["\x00Symfony\Component\Mime\Part\AbstractMultipartPart\x00boundary"];
$this->parts = $data['parts'] ?? $data["\x00Symfony\Component\Mime\Part\AbstractMultipartPart\x00parts"];
}

private function getBoundary(): string
{
return $this->boundary ??= strtr(base64_encode(random_bytes(6)), '+/', '-_');
Expand Down
10 changes: 10 additions & 0 deletions 10 src/Symfony/Component/Mime/Part/AbstractPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ public function toIterable(): iterable
yield from $this->bodyToIterable();
}

public function __serialize(): array
{
return ['headers' => $this->headers];
}

public function __unserialize(array $data): void
{
$this->headers = $data['headers'] ?? $data["\x00Symfony\Component\Mime\Part\AbstractPart\x00headers"] ?? $data["\x00*\x00_headers"];
}

public function asDebugString(): string
{
return $this->getMediaType().'/'.$this->getMediaSubtype();
Expand Down
26 changes: 25 additions & 1 deletion 26 src/Symfony/Component/Mime/Part/DataPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
*/
class DataPart extends TextPart
{
/** @internal */
/**
* @internal
* @deprecated since Symfony 6.4, to be removed in 7.0
*/
protected array $_parent;

private ?string $filename = null;
Expand Down Expand Up @@ -129,8 +132,13 @@ private function generateContentId(): string
return bin2hex(random_bytes(16)).'@symfony';
}

/**
* @deprecated since Symfony 6.4, to be removed in 7.0
*/
public function __sleep(): array
{
trigger_deprecation('symfony/mime', '6.4', 'The "%s()" method is deprecated and will be removed in Symfony 7.0.', __METHOD__);

// converts the body to a string
parent::__sleep();

Expand All @@ -145,10 +153,14 @@ public function __sleep(): array
}

/**
* @deprecated since Symfony 6.4, to be removed in 7.0
*
* @return void
*/
public function __wakeup()
{
trigger_deprecation('symfony/mime', '6.4', 'The "%s()" method is deprecated and will be removed in Symfony 7.0.', __METHOD__);

$r = new \ReflectionProperty(AbstractPart::class, 'headers');
$r->setValue($this, $this->_headers);
unset($this->_headers);
Expand All @@ -165,4 +177,16 @@ public function __wakeup()
}
unset($this->_parent);
}

public function __serialize(): array
{
return [...parent::__serialize(), 'filename' => $this->filename, 'mediaType' => $this->mediaType];
}

public function __unserialize(array $data): void
{
parent::__unserialize($data);
$this->filename = \array_key_exists('filename', $data) ? $data['filename'] : $data["\x00Symfony\Component\Mime\Part\DataPart\x00filename"];
$this->mediaType = $data['mediaType'] ?? $data["\x00Symfony\Component\Mime\Part\DataPart\x00mediaType"];
}
}
20 changes: 20 additions & 0 deletions 20 src/Symfony/Component/Mime/Part/MessagePart.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,33 @@ public function bodyToIterable(): iterable
return $this->message->toIterable();
}

/**
* @deprecated since Symfony 6.4, to be removed in 7.0
*/
public function __sleep(): array
{
trigger_deprecation('symfony/mime', '6.4', 'The "%s()" method is deprecated and will be removed in Symfony 7.0.', __METHOD__);

return ['message'];
}

/**
* @deprecated since Symfony 6.4, to be removed in 7.0
*/
public function __wakeup(): void
{
trigger_deprecation('symfony/mime', '6.4', 'The "%s()" method is deprecated and will be removed in Symfony 7.0.', __METHOD__);

$this->__construct($this->message);
}

public function __serialize(): array
{
return ['message' => $this->message];
}

public function __unserialize(array $data): void
{
$this->__construct($data['message'] ?? $data["\x00Symfony\Component\Mime\Part\MessagePart\x00message"]);
}
}
11 changes: 11 additions & 0 deletions 11 src/Symfony/Component/Mime/Part/Multipart/FormDataPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ public function getParts(): array
return $this->prepareFields($this->fields);
}

public function __serialize(): array
{
return [...parent::__serialize(), 'fields' => $this->fields];
}

public function __unserialize(array $data): void
{
parent::__unserialize($data);
$this->fields = $data['fields'] ?? $data["\x00Symfony\Component\Mime\Part\Multipart\FormDataPart\x00fields"];
}

private function prepareFields(array $fields): array
{
$values = [];
Expand Down
11 changes: 11 additions & 0 deletions 11 src/Symfony/Component/Mime/Part/Multipart/RelatedPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ public function getMediaSubtype(): string
return 'related';
}

public function __serialize(): array
{
return [...parent::__serialize(), 'mainPart' => $this->mainPart];
}

public function __unserialize(array $data): void
{
parent::__unserialize($data);
$this->mainPart = $data['mainPart'] ?? $data["\x00Symfony\Component\Mime\Part\Multipart\RelatedPart\x00mainPart"];
}

private function generateContentId(): string
{
return bin2hex(random_bytes(16)).'@symfony';
Expand Down
34 changes: 33 additions & 1 deletion 34 src/Symfony/Component/Mime/Part/SMimePart.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
*/
class SMimePart extends AbstractPart
{
/** @internal */
/**
* @internal
* @deprecated since Symfony 6.4, to be removed in 7.0
*/
protected Headers $_headers;

private iterable|string $body;
Expand Down Expand Up @@ -90,8 +93,13 @@ public function getPreparedHeaders(): Headers
return $headers;
}

/**
* @deprecated since Symfony 6.4, to be removed in 7.0
*/
public function __sleep(): array
{
trigger_deprecation('symfony/mime', '6.4', 'The "%s()" method is deprecated and will be removed in Symfony 7.0.', __METHOD__);

// convert iterables to strings for serialization
if (is_iterable($this->body)) {
$this->body = $this->bodyToString();
Expand All @@ -102,10 +110,34 @@ public function __sleep(): array
return ['_headers', 'body', 'type', 'subtype', 'parameters'];
}

/**
* @deprecated since Symfony 6.4, to be removed in 7.0
*/
public function __wakeup(): void
{
trigger_deprecation('symfony/mime', '6.4', 'The "%s()" method is deprecated and will be removed in Symfony 7.0.', __METHOD__);

$r = new \ReflectionProperty(AbstractPart::class, 'headers');
$r->setValue($this, $this->_headers);
unset($this->_headers);
}

public function __serialize(): array
{
// convert iterables to strings for serialization
if (is_iterable($this->body)) {
$this->body = $this->bodyToString();
}

return [...parent::__serialize(), 'body' => $this->body, 'type' => $this->type, 'subtype' => $this->subtype, 'parameters' => $this->parameters];
}

public function __unserialize(array $data): void
{
parent::__unserialize($data);
$this->body = $data['body'] ?? $data["\x00Symfony\Component\Mime\Part\SMimePart\x00body"];
$this->type = $data['type'] ?? $data["\x00Symfony\Component\Mime\Part\SMimePart\x00type"];
$this->subtype = $data['subtype'] ?? $data["\x00Symfony\Component\Mime\Part\SMimePart\x00subtype"];
$this->parameters = $data['parameters'] ?? $data["\x00Symfony\Component\Mime\Part\SMimePart\x00parameters"];
}
}
36 changes: 35 additions & 1 deletion 36 src/Symfony/Component/Mime/Part/TextPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
*/
class TextPart extends AbstractPart
{
/** @internal */
/**
* @internal
* @deprecated since Symfony 6.4, to be removed in 7.0
*/
protected Headers $_headers;

private static array $encoders = [];
Expand Down Expand Up @@ -219,8 +222,13 @@ private function chooseEncoding(): string
return 'quoted-printable';
}

/**
* @deprecated since Symfony 6.4, to be removed in 7.0
*/
public function __sleep(): array
{
trigger_deprecation('symfony/mime', '6.4', 'The "%s()" method is deprecated and will be removed in Symfony 7.0.', __METHOD__);

// convert resources to strings for serialization
if (null !== $this->seekable || $this->body instanceof File) {
$this->body = $this->getBody();
Expand All @@ -233,12 +241,38 @@ public function __sleep(): array
}

/**
* @deprecated since Symfony 6.4, to be removed in 7.0
*
* @return void
*/
public function __wakeup()
{
trigger_deprecation('symfony/mime', '6.4', 'The "%s()" method is deprecated and will be removed in Symfony 7.0.', __METHOD__);

$r = new \ReflectionProperty(AbstractPart::class, 'headers');
$r->setValue($this, $this->_headers);
unset($this->_headers);
}

public function __serialize(): array
{
// convert resources to strings for serialization
if (null !== $this->seekable || $this->body instanceof File) {
$this->body = $this->getBody();
$this->seekable = null;
}

return [...parent::__serialize(), 'body' => $this->body, 'charset' => $this->charset, 'subtype' => $this->subtype, 'disposition' => $this->disposition, 'name' => $this->name, 'encoding' => $this->encoding];
}

public function __unserialize(array $data): void
{
parent::__unserialize($data);
$this->body = $data['body'] ?? $data["\x00Symfony\Component\Mime\Part\TextPart\x00body"] ?? $data["\x00*\x00_parent"]['body'];
$this->charset = \array_key_exists('charset', $data) ? $data['charset'] : (\array_key_exists("\x00Symfony\Component\Mime\Part\TextPart\x00charset", $data) ? $data["\x00Symfony\Component\Mime\Part\TextPart\x00charset"] : $data["\x00*\x00_parent"]['charset']);
$this->subtype = $data['subtype'] ?? $data["\x00Symfony\Component\Mime\Part\TextPart\x00subtype"] ?? $data["\x00*\x00_parent"]['subtype'];
$this->disposition = \array_key_exists('disposition', $data) ? $data['disposition'] : (\array_key_exists("\x00Symfony\Component\Mime\Part\TextPart\x00disposition", $data) ? $data["\x00Symfony\Component\Mime\Part\TextPart\x00disposition"] : $data["\x00*\x00_parent"]['disposition']);
$this->name = \array_key_exists('name', $data) ? $data['name'] : (\array_key_exists("\x00Symfony\Component\Mime\Part\TextPart\x00name", $data) ? $data["\x00Symfony\Component\Mime\Part\TextPart\x00name"] : $data["\x00*\x00_parent"]['name']);
$this->encoding = $data['encoding'] ?? $data["\x00Symfony\Component\Mime\Part\TextPart\x00encoding"] ?? $data["\x00*\x00_parent"]['encoding'];
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.