|
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,10 +2641,32 @@ 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) |
| 2648 | + */ |
| 2649 | + public function __serialize(): array |
| 2650 | + { |
| 2651 | + if (new ReflectionMethod($this, '__sleep')->getDeclaringClass() !== self::class) { |
| 2652 | + trigger_deprecation( |
| 2653 | + 'doctrine/mongodb-odm', |
| 2654 | + '2.16', |
| 2655 | + 'The method __sleep() is deprecated. Implement and use %s() instead.', |
| 2656 | + __METHOD__, |
| 2657 | + ); |
| 2658 | + } |
| 2659 | + |
| 2660 | + $data = []; |
| 2661 | + foreach ($this->__sleep() as $field) { |
| 2662 | + $data[$field] = $this->$field; |
| 2663 | + } |
| 2664 | + |
| 2665 | + return $data; |
| 2666 | + } |
| 2667 | + |
| 2668 | + /** |
| 2669 | + * @deprecated Implement and use __serialize() instead. |
2647 | 2670 | * |
2648 | 2671 | * @return array The names of all the fields that should be serialized. |
2649 | 2672 | */ |
@@ -2700,7 +2723,7 @@ public function __sleep() |
2700 | 2723 | $serialized[] = 'isQueryResultDocument'; |
2701 | 2724 | } |
2702 | 2725 |
|
2703 | | - if ($this->isView()) { |
| 2726 | + if ($this->isView) { |
2704 | 2727 | $serialized[] = 'isView'; |
2705 | 2728 | $serialized[] = 'rootClass'; |
2706 | 2729 | } |
@@ -2745,8 +2768,18 @@ public function __sleep() |
2745 | 2768 | } |
2746 | 2769 |
|
2747 | 2770 | /** |
2748 | | - * Restores some state that cannot be serialized/unserialized. |
| 2771 | + * Restores the serialized values and some state that cannot be serialized/unserialized. |
2749 | 2772 | */ |
| 2773 | + public function __unserialize(array $data): void |
| 2774 | + { |
| 2775 | + foreach ($data as $field => $value) { |
| 2776 | + $this->$field = $value; |
| 2777 | + } |
| 2778 | + |
| 2779 | + $this->__wakeup(); |
| 2780 | + } |
| 2781 | + |
| 2782 | + /** @deprecated Implement and use __unserialize() instead. */ |
2750 | 2783 | public function __wakeup(): void |
2751 | 2784 | { |
2752 | 2785 | // Restore ReflectionClass and properties |
|
0 commit comments