8000 [DoctrineBridge] Add check for lazy object interface by maxbaldanza · Pull Request #53079 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DoctrineBridge] Add check for lazy object interface #53079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add check for lazy object interface
In Symfony 6.4 lazy loading of ghost
proxies is the default.

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`
  • Loading branch information
maxbaldanza committed Dec 14, 2023
commit 7ed961e57e432b7065e08d195c70bacc20eeff4c
8 changes: 8 additions & 0 deletions src/Symfony/Bridge/Doctrine/ManagerRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use ProxyManager\Proxy\LazyLoadingInterface;
use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\VarExporter\LazyObjectInterface;

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

if ($manager instanceof LazyObjectInterface) {
if (!$manager->resetLazyObject()) {
throw new \LogicException(sprintf('Resetting a non-lazy manager service is not supported. Declare the "%s" service as lazy.', $name));
}

return;
}
if (!$manager instanceof LazyLoadingInterface) {
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".'));
}
Expand Down
0