File tree Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Original file line number Diff line number Diff line change 66use Doctrine \ORM \ORMException ;
77use Doctrine \Persistence \Proxy ;
88use ProxyManager \Proxy \LazyLoadingInterface ;
9+ use ReflectionClass ;
910use Symfony \Bridge \Doctrine \ManagerRegistry ;
1011use Symfony \Component \DependencyInjection \Container ;
1112use Symfony \Component \VarExporter \LazyObjectInterface ;
1213use Symfony \Contracts \Service \ResetInterface ;
1314
1415use function array_keys ;
1516use function assert ;
17+ use function method_exists ;
18+
19+ use const PHP_VERSION_ID ;
1620
1721/**
1822 * References all Doctrine connections and entity managers in a given Container.
@@ -79,10 +83,27 @@ private function resetOrClearManager(string $managerName, string $serviceId): vo
7983
8084 assert ($ manager instanceof EntityManagerInterface);
8185
82- if ((! $ manager instanceof LazyLoadingInterface && ! $ manager instanceof LazyObjectInterface) || $ manager ->isOpen ()) {
83- $ manager ->clear ();
86+ // Determine if the version of symfony/dependency-injection is >= 7.3
87+ /** @phpstan-ignore function.alreadyNarrowedType */
88+ $ sfNativeLazyObjects = method_exists ('Symfony\Component\DependencyInjection\ContainerBuilder ' , 'findTaggedResourceIds ' );
8489
85- return ;
90+ if (PHP_VERSION_ID < 80400 || ! $ sfNativeLazyObjects ) {
91+ if ((! $ manager instanceof LazyLoadingInterface && ! $ manager instanceof LazyObjectInterface) || $ manager ->isOpen ()) {
92+ $ manager ->clear ();
93+
94+ return ;
95+ }
96+ } else {
97+ $ r = new ReflectionClass ($ manager );
98+ if ($ r ->isUninitializedLazyObject ($ manager )) {
99+ return ;
100+ }
101+
102+ if ($ manager ->isOpen ()) {
103+ $ manager ->clear ();
104+
105+ return ;
106+ }
86107 }
87108
88109 $ this ->resetManager ($ managerName );
You can’t perform that action at this time.
0 commit comments