@@ -2460,110 +2460,114 @@ public function mapField(array $mapping): array
24602460 * - reflClass (ReflectionClass)
24612461 * - propertyAccessors (ReflectionProperty array)
24622462 *
2463- * @return array The names of all the fields that should be serialized.
2464- */
2465- public function __sleep (): array
2466- {
2467- // This metadata is always serialized/cached.
2468- $ serialized = [
2469- 'fieldMappings ' ,
2470- 'associationMappings ' ,
2471- 'identifier ' ,
2472- 'name ' ,
2473- 'db ' ,
2474- 'collection ' ,
2475- 'readPreference ' ,
2476- 'readPreferenceTags ' ,
2477- 'writeConcern ' ,
2478- 'rootDocumentName ' ,
2479- 'generatorType ' ,
2480- 'generatorOptions ' ,
2481- 'idGenerator ' ,
2482- 'indexes ' ,
2483- 'shardKey ' ,
2484- 'timeSeriesOptions ' ,
2463+ * @return array<string, mixed>
2464+ */
2465+ public function __serialize (): array
2466+ {
2467+ $ data = [
2468+ 'fieldMappings ' => $ this ->fieldMappings ,
2469+ 'associationMappings ' => $ this ->associationMappings ,
2470+ 'identifier ' => $ this ->identifier ,
2471+ 'name ' => $ this ->name ,
2472+ 'db ' => $ this ->db ,
2473+ 'collection ' => $ this ->collection ,
2474+ 'readPreference ' => $ this ->readPreference ,
2475+ 'readPreferenceTags ' => $ this ->readPreferenceTags ,
2476+ 'writeConcern ' => $ this ->writeConcern ,
2477+ 'rootDocumentName ' => $ this ->rootDocumentName ,
2478+ 'generatorType ' => $ this ->generatorType ,
2479+ 'generatorOptions ' => $ this ->generatorOptions ,
2480+ 'idGenerator ' => $ this ->idGenerator ,
2481+ 'indexes ' => $ this ->indexes ,
2482+ 'shardKey ' => $ this ->shardKey ,
2483+ 'timeSeriesOptions ' => $ this ->timeSeriesOptions ,
24852484 ];
24862485
2487- // The rest of the metadata is only serialized if necessary.
24882486 if ($ this ->changeTrackingPolicy !== self ::CHANGETRACKING_DEFERRED_IMPLICIT ) {
2489- $ serialized [ ] = ' changeTrackingPolicy ' ;
2487+ $ data [ ' changeTrackingPolicy ' ] = $ this -> changeTrackingPolicy ;
24902488 }
24912489
24922490 if ($ this ->customRepositoryClassName ) {
2493- $ serialized [ ] = ' customRepositoryClassName ' ;
2491+ $ data [ ' customRepositoryClassName ' ] = $ this -> customRepositoryClassName ;
24942492 }
24952493
24962494 if ($ this ->inheritanceType !== self ::INHERITANCE_TYPE_NONE || $ this ->discriminatorField !== null ) {
2497- $ serialized [] = ' inheritanceType ' ;
2498- $ serialized [] = ' discriminatorField ' ;
2499- $ serialized [] = ' discriminatorValue ' ;
2500- $ serialized [] = ' discriminatorMap ' ;
2501- $ serialized [ ] = ' defaultDiscriminatorValue ' ;
2502- $ serialized [] = ' parentClasses ' ;
2503- $ serialized [] = ' subClasses ' ;
2495+ $ data [ ' inheritanceType ' ] = $ this -> inheritanceType ;
2496+ $ data [ ' discriminatorField ' ] = $ this -> discriminatorField ;
2497+ $ data [ ' discriminatorValue ' ] = $ this -> discriminatorValue ;
2498+ $ data [ ' discriminatorMap ' ] = $ this -> discriminatorMap ;
2499+ $ data [ ' defaultDiscriminatorValue ' ] = $ this -> defaultDiscriminatorValue ;
2500+ $ data [ ' parentClasses ' ] = $ this -> parentClasses ;
2501+ $ data [ ' subClasses ' ] = $ this -> subClasses ;
25042502 }
25052503
25062504 if ($ this ->isMappedSuperclass ) {
2507- $ serialized [ ] = ' isMappedSuperclass ' ;
2505+ $ data [ ' isMappedSuperclass ' ] = $ this -> isMappedSuperclass ;
25082506 }
25092507
25102508 if ($ this ->isEmbeddedDocument ) {
2511- $ serialized [ ] = ' isEmbeddedDocument ' ;
2509+ $ data [ ' isEmbeddedDocument ' ] = $ this -> isEmbeddedDocument ;
25122510 }
25132511
25142512 if ($ this ->isQueryResultDocument ) {
2515- $ serialized [ ] = ' isQueryResultDocument ' ;
2513+ $ data [ ' isQueryResultDocument ' ] = $ this -> isQueryResultDocument ;
25162514 }
25172515
2518- if ($ this ->isView () ) {
2519- $ serialized [] = ' isView ' ;
2520- $ serialized [ ] = ' rootClass ' ;
2516+ if ($ this ->isView ) {
2517+ $ data [ ' isView ' ] = $ this -> isView ;
2518+ $ data [ ' rootClass ' ] = $ this -> rootClass ;
25212519 }
25222520
25232521 if ($ this ->isFile ) {
2524- $ serialized [] = ' isFile ' ;
2525- $ serialized [] = ' bucketName ' ;
2526- $ serialized [ ] = ' chunkSizeBytes ' ;
2522+ $ data [ ' isFile ' ] = $ this -> isFile ;
2523+ $ data [ ' bucketName ' ] = $ this -> bucketName ;
2524+ $ data [ ' chunkSizeBytes ' ] = $ this -> chunkSizeBytes ;
25272525 }
25282526
25292527 if ($ this ->isVersioned ) {
2530- $ serialized [] = ' isVersioned ' ;
2531- $ serialized [ ] = ' versionField ' ;
2528+ $ data [ ' isVersioned ' ] = $ this -> isVersioned ;
2529+ $ data [ ' versionField ' ] = $ this -> versionField ;
25322530 }
25332531
25342532 if ($ this ->isLockable ) {
2535- $ serialized [ ] = ' isLockable ' ;
2536- $ serialized [] = ' lockField ' ;
2533+ $ data [ ' isLockable ' ] = $ this -> isLockable ;
2534+ $ data [ ' lockField ' ] = $ this -> lockField ;
25372535 }
25382536
25392537 if ($ this ->lifecycleCallbacks ) {
2540- $ serialized [ ] = ' lifecycleCallbacks ' ;
2538+ $ data [ ' lifecycleCallbacks ' ] = $ this -> lifecycleCallbacks ;
25412539 }
25422540
25432541 if ($ this ->collectionCapped ) {
2544- $ serialized [ ] = ' collectionCapped ' ;
2545- $ serialized [] = ' collectionSize ' ;
2546- $ serialized [] = ' collectionMax ' ;
2542+ $ data [ ' collectionCapped ' ] = $ this -> collectionCapped ;
2543+ $ data [ ' collectionSize ' ] = $ this -> collectionSize ;
2544+ $ data [ ' collectionMax ' ] = $ this -> collectionMax ;
25472545 }
25482546
25492547 if ($ this ->isReadOnly ) {
2550- $ serialized [ ] = ' isReadOnly ' ;
2548+ $ data [ ' isReadOnly ' ] = $ this -> isReadOnly ;
25512549 }
25522550
25532551 if ($ this ->validator !== null ) {
2554- $ serialized [] = ' validator ' ;
2555- $ serialized [ ] = ' validationAction ' ;
2556- $ serialized [] = ' validationLevel ' ;
2552+ $ data [ ' validator ' ] = $ this -> validator ;
2553+ $ data [ ' validationAction ' ] = $ this -> validationAction ;
2554+ $ data [ ' validationLevel ' ] = $ this -> validationLevel ;
25572555 }
25582556
2559- return $ serialized ;
2557+ return $ data ;
25602558 }
25612559
25622560 /**
2563- * Restores some state that cannot be serialized/unserialized.
2561+ * Restores state after unserialization.
2562+ *
2563+ * @param array<string, mixed> $data
25642564 */
2565- public function __wakeup ( ): void
2565+ public function __unserialize ( array $ data ): void
25662566 {
2567+ foreach ($ data as $ property => $ value ) {
2568+ $ this ->$ property = $ value ;
2569+ }
2570+
25672571 // Restore ReflectionClass and properties
25682572 $ this ->reflClass = new ReflectionClass ($ this ->name );
25692573 $ this ->instantiator = new Instantiator ();
0 commit comments