@@ -90,60 +90,17 @@ private static function generateClassFor(object $object): string
9090 $ proxyCode ,
9191 [
9292 'implements \Symfony\Component\VarExporter\LazyObjectInterface ' => \sprintf ('implements \%s, \Symfony\Component\VarExporter\LazyObjectInterface ' , Proxy::class),
93- 'use \Symfony\Component\VarExporter\LazyProxyTrait; ' => \sprintf ("use \\%s; \n use \\%s; " , IsProxy::class, LazyProxyTrait::class),
93+ 'use \Symfony\Component\VarExporter\LazyProxyTrait ' => \sprintf ("use \\%s; \n use \\%s " , IsProxy::class, LazyProxyTrait::class),
9494 'if (isset($this->lazyObjectState)) { ' => "\$this->_autoRefresh(); \n\n if (isset( \$this->lazyObjectReal)) { " ,
9595 '\func_get_args() ' => '$this->unproxyArgs(\func_get_args()) ' ,
9696 ],
9797 );
9898
99- $ proxyCode = self ::handleContravarianceInUnserializeMethod ($ reflectionClass , $ proxyCode );
100-
10199 eval ($ proxyCode ); // @phpstan-ignore-line
102100
103101 return $ proxyClass ;
104102 }
105103
106- /**
107- * @template T of object
108- *
109- * @param \ReflectionClass<T> $class
110- *
111- * Monkey patch for https://github.com/symfony/symfony/pull/57460, until the PR is released.
112- */
113- private static function handleContravarianceInUnserializeMethod (\ReflectionClass $ class , string $ proxyCode ): string
114- {
115- if (
116- !str_contains ($ proxyCode , '__doUnserialize ' )
117- && $ class ->hasMethod ('__unserialize ' )
118- && null !== ($ unserializeParameter = $ class ->getMethod ('__unserialize ' )->getParameters ()[0 ] ?? null )
119- && null === $ unserializeParameter ->getType ()
120- ) {
121- $ proxyCode = str_replace (
122- 'use \Symfony\Component\VarExporter\LazyProxyTrait; ' ,
123- <<<EOPHP
124- use \Symfony\Component\VarExporter\LazyProxyTrait {
125- __unserialize as private _doUnserialize;
126- }
127- EOPHP ,
128- $ proxyCode
129- );
130-
131- $ unserializeMethod = <<<EOPHP
132-
133- public function __unserialize( \$data): void
134- {
135- \$this->_doUnserialize( \$data);
136- }
137-
138- EOPHP ;
139-
140- $ lastCurlyBraceOffset = strrpos ($ proxyCode , '} ' ) ?: throw new \LogicException ('Last curly brace offset not found. ' );
141- $ proxyCode = substr_replace ($ proxyCode , $ unserializeMethod ."} " , $ lastCurlyBraceOffset , 1 );
142- }
143-
144- return $ proxyCode ;
145- }
146-
147104 /**
148105 * @param class-string $class
149106 */
0 commit comments