|
34 | 34 | use ProxyManager\Proxy\GhostObjectInterface; |
35 | 35 | use ReflectionClass; |
36 | 36 | use ReflectionEnum; |
| 37 | +use ReflectionMethod; |
37 | 38 | use ReflectionNamedType; |
38 | 39 | use ReflectionProperty; |
39 | 40 | use Symfony\Component\Uid\UuidV1; |
@@ -2640,12 +2641,36 @@ public function mapField(array $mapping): array |
2640 | 2641 | * That means any metadata properties that are not set or empty or simply have |
2641 | 2642 | * their default value are NOT serialized. |
2642 | 2643 | * |
2643 | | - * Parts that are also NOT serialized because they cannot be properly unserialized: |
2644 | | - * - reflClass (ReflectionClass) |
2645 | | - * - reflFields (ReflectionProperty array) |
2646 | | - * - propertyAccessors (ReflectionProperty array) |
| 2644 | + * Parts that are also NOT serialized because they cannot be properly unserialized: |
| 2645 | + * - reflClass (ReflectionClass) |
| 2646 | + * - reflFields (ReflectionProperty array) |
| 2647 | + * - propertyAccessors (ReflectionProperty array) |
2647 | 2648 | * |
2648 | | - * @return array The names of all the fields that should be serialized. |
| 2649 | + * @return array<string, mixed> The serialized data. |
| 2650 | + */ |
| 2651 | + public function __serialize(): array |
| 2652 | + { |
| 2653 | + if (new ReflectionMethod($this, '__sleep')->getDeclaringClass() !== self::class) { |
| 2654 | + trigger_deprecation( |
| 2655 | + 'doctrine/mongodb-odm', |
| 2656 | + '2.16', |
| 2657 | + 'The method __sleep() is deprecated. Implement and use %s() instead.', |
| 2658 | + __METHOD__, |
| 2659 | + ); |
| 2660 | + } |
| 2661 | + |
| 2662 | + $data = []; |
| 2663 | + foreach ($this->__sleep() as $field) { |
| 2664 | + $data[$field] = $this->$field; |
| 2665 | + } |
| 2666 | + |
| 2667 | + return $data; |
| 2668 | + } |
| 2669 | + |
| 2670 | + /** |
| 2671 | + * @deprecated |
| 2672 | + * |
| 2673 | + * @return list<string> The names of all the fields that should be serialized. |
2649 | 2674 | */ |
2650 | 2675 | public function __sleep() |
2651 | 2676 | { |
@@ -2700,7 +2725,7 @@ public function __sleep() |
2700 | 2725 | $serialized[] = 'isQueryResultDocument'; |
2701 | 2726 | } |
2702 | 2727 |
|
2703 | | - if ($this->isView()) { |
| 2728 | + if ($this->isView) { |
2704 | 2729 | $serialized[] = 'isView'; |
2705 | 2730 | $serialized[] = 'rootClass'; |
2706 | 2731 | } |
@@ -2745,8 +2770,20 @@ public function __sleep() |
2745 | 2770 | } |
2746 | 2771 |
|
2747 | 2772 | /** |
2748 | | - * Restores some state that cannot be serialized/unserialized. |
| 2773 | + * Restores the serialized values and some state that cannot be serialized/unserialized. |
| 2774 | + * |
| 2775 | + * @param array<string, mixed> $data The serialized data. |
2749 | 2776 | */ |
| 2777 | + public function __unserialize(array $data): void |
| 2778 | + { |
| 2779 | + foreach ($data as $field => $value) { |
| 2780 | + $this->$field = $value; |
| 2781 | + } |
| 2782 | + |
| 2783 | + $this->__wakeup(); |
| 2784 | + } |
| 2785 | + |
| 2786 | + /** @deprecated */ |
2750 | 2787 | public function __wakeup(): void |
2751 | 2788 | { |
2752 | 2789 | // Restore ReflectionClass and properties |
|
0 commit comments