Skip to content

Commit ddf3bcb

Browse files
committed
bug symfony#53079 [DoctrineBridge] Add check for lazy object interface (maxbaldanza)
This PR was merged into the 5.4 branch. Discussion ---------- [DoctrineBridge] Add check for lazy object interface In Symfony 6.4 lazy loading of ghost proxies is used out of the box. This means if using 6.4 components with the 5.4 version of the doctrine bridge you get the following error when trying to reset the entity manager: ``` Resetting a non-lazy manager service is not supported. Declare the "doctrine.orm.default_entity_manager" service as lazy. ``` The entity manager is set as lazy already in our case but it extends `\Symfony\Component\VarExporter\LazyObjectInterface` instead of the `LazyLoadingInterface` that's expected | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | | License | MIT Commits ------- 7ed961e Add check for lazy object interface
2 parents 30ae143 + 7ed961e commit ddf3bcb

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/Symfony/Bridge/Doctrine/ManagerRegistry.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ProxyManager\Proxy\LazyLoadingInterface;
1717
use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator;
1818
use Symfony\Component\DependencyInjection\Container;
19+
use Symfony\Component\VarExporter\LazyObjectInterface;
1920

2021
/**
2122
* References Doctrine connections and entity/document managers.
@@ -51,6 +52,13 @@ protected function resetService($name)
5152
}
5253
$manager = $this->container->get($name);
5354

55+
if ($manager instanceof LazyObjectInterface) {
56+
if (!$manager->resetLazyObject()) {
57+
throw new \LogicException(sprintf('Resetting a non-lazy manager service is not supported. Declare the "%s" service as lazy.', $name));
58+
}
59+
60+
return;
61+
}
5462
if (!$manager instanceof LazyLoadingInterface) {
5563
throw new \LogicException('Resetting a non-lazy manager service is not supported. '.(interface_exists(LazyLoadingInterface::class) && class_exists(RuntimeInstantiator::class) ? sprintf('Declare the "%s" service as lazy.', $name) : 'Try running "composer require symfony/proxy-manager-bridge".'));
5664
}

0 commit comments

Comments
 (0)