@@ -45,31 +45,60 @@ protected function resetService($name): void
4545
4646 return ;
4747 }
48- if (!$ manager instanceof LazyLoadingInterface) {
49- throw new \LogicException (\sprintf ('Resetting a non-lazy manager service is not supported. Declare the "%s" service as lazy. ' , $ name ));
48+ if (\PHP_VERSION_ID < 80400 ) {
49+ if (!$ manager instanceof LazyLoadingInterface) {
50+ throw new \LogicException (\sprintf ('Resetting a non-lazy manager service is not supported. Declare the "%s" service as lazy. ' , $ name ));
51+ }
52+ trigger_deprecation ('symfony/doctrine-bridge ' , '7.3 ' , 'Support for proxy-manager is deprecated. ' );
53+
54+ if ($ manager instanceof GhostObjectInterface) {
55+ throw new \LogicException ('Resetting a lazy-ghost-object manager service is not supported. ' );
56+ }
57+ $ manager ->setProxyInitializer (\Closure::bind (
58+ function (&$ wrappedInstance , LazyLoadingInterface $ manager ) use ($ name ) {
59+ $ name = $ this ->aliases [$ name ] ?? $ name ;
60+ $ wrappedInstance = match (true ) {
61+ isset ($ this ->fileMap [$ name ]) => $ this ->load ($ this ->fileMap [$ name ], false ),
62+ (new \ReflectionMethod ($ this , $ method = $ this ->methodMap [$ name ]))->isStatic () => $ this ->{$ method }($ this , false ),
63+ default => $ this ->{$ method }(false ),
64+ };
65+ $ manager ->setProxyInitializer (null );
66+
67+ return true ;
68+ },
69+ $ this ->container ,
70+ Container::class
71+ ));
72+
73+ return ;
5074 }
51- if ($ manager instanceof GhostObjectInterface) {
52- throw new \LogicException ('Resetting a lazy-ghost-object manager service is not supported. ' );
75+
76+ $ r = new \ReflectionClass ($ manager );
77+
78+ if ($ r ->isUninitializedLazyObject ($ manager )) {
79+ return ;
80+ }
81+
82+ try {
83+ $ r ->resetAsLazyProxy ($ manager , \Closure::bind (
84+ function () use ($ name ) {
85+ $ name = $ this ->aliases [$ name ] ?? $ name ;
86+
87+ return match (true ) {
88+ isset ($ this ->fileMap [$ name ]) => $ this ->load ($ this ->fileMap [$ name ], false ),
89+ (new \ReflectionMethod ($ this , $ method = $ this ->methodMap [$ name ]))->isStatic () => $ this ->{$ method }($ this , false ),
90+ default => $ this ->{$ method }(false ),
91+ };
92+ },
93+ $ this ->container ,
94+ Container::class
95+ ));
96+ } catch (\Error $ e ) {
97+ if (__FILE__ !== $ e ->getFile ()) {
98+ throw $ e ;
99+ }
100+
101+ throw new \LogicException (\sprintf ('Resetting a non-lazy manager service is not supported. Declare the "%s" service as lazy. ' , $ name ), 0 , $ e );
53102 }
54- $ manager ->setProxyInitializer (\Closure::bind (
55- function (&$ wrappedInstance , LazyLoadingInterface $ manager ) use ($ name ) {
56- if (isset ($ this ->aliases [$ name ])) {
57- $ name = $ this ->aliases [$ name ];
58- }
59- if (isset ($ this ->fileMap [$ name ])) {
60- $ wrappedInstance = $ this ->load ($ this ->fileMap [$ name ], false );
61- } elseif ((new \ReflectionMethod ($ this , $ this ->methodMap [$ name ]))->isStatic ()) {
62- $ wrappedInstance = $ this ->{$ this ->methodMap [$ name ]}($ this , false );
63- } else {
64- $ wrappedInstance = $ this ->{$ this ->methodMap [$ name ]}(false );
65- }
66-
67- $ manager ->setProxyInitializer (null );
68-
69- return true ;
70- },
71- $ this ->container ,
72- Container::class
73- ));
74103 }
75104}
0 commit comments