@@ -366,8 +366,54 @@ public function startsWith(string|iterable|AbstractString $prefix): bool
366366 return $ prefix === $ grapheme ;
367367 }
368368
369+ public function __unserialize (array $ data ): void
370+ {
371+ if ($ wakeup = self ::class !== (new \ReflectionMethod ($ this , '__wakeup ' ))->class ) {
372+ trigger_deprecation ('symfony/string ' , '7.4 ' , 'Implementing "%s::__wakeup()" is deprecated, use "__unserialize()" instead. ' , get_debug_type ($ this ));
373+ }
374+
375+ try {
376+ if (\in_array (array_keys ($ data ), [['string ' ], ["\0* \0string " ]], true )) {
377+ $ this ->string = $ data ['string ' ] ?? $ data ["\0* \0string " ];
378+
379+ if ($ wakeup ) {
380+ $ this ->__wakeup ();
381+ }
382+
383+ return ;
384+ }
385+
386+ trigger_deprecation ('symfony/string ' , '7.4 ' , 'Passing more than just key "string" to "%s::__unserialize()" is deprecated, populate properties in "%s::__unserialize()" instead. ' , self ::class, get_debug_type ($ this ));
387+
388+ \Closure::bind (function ($ data ) use ($ wakeup ) {
389+ foreach ($ data as $ key => $ value ) {
390+ $ this ->{("\0" === $ key [0 ] ?? '' ) ? substr ($ key , 1 + strrpos ($ key , "\0" )) : $ key } = $ value ;
391+ }
392+
393+ if ($ wakeup ) {
394+ $ this ->__wakeup ();
395+ }
396+ }, $ this , static ::class)($ data );
397+ } finally {
398+ if (!$ wakeup ) {
399+ if (!\is_string ($ this ->string )) {
400+ throw new \BadMethodCallException ('Cannot unserialize ' .__CLASS__ );
401+ }
402+
403+ normalizer_is_normalized ($ this ->string ) ?: $ this ->string = normalizer_normalize ($ this ->string );
404+ }
405+ }
406+ }
407+
408+ /**
409+ * @internal since Symfony 7.4, will be removed in 8.0
410+ *
411+ * @final since Symfony 7.4, will be removed in 8.0
412+ */
369413 public function __wakeup (): void
370414 {
415+ trigger_deprecation ('symfony/string ' , '7.4 ' , 'Calling "%s::__wakeup()" is deprecated, use "__unserialize()" instead. ' , get_debug_type ($ this ));
416+
371417 if (!\is_string ($ this ->string )) {
372418 throw new \BadMethodCallException ('Cannot unserialize ' .__CLASS__ );
373419 }
0 commit comments