Skip to content

Lazily resolve ManagerRegistry in EntityManagerProvider #664

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 3 commits into from
May 21, 2025
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
7 changes: 4 additions & 3 deletions src/Console/EntityManagerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Tools\Console\EntityManagerProvider as DoctrineEntityManagerProvider;
use Doctrine\Persistence\ManagerRegistry;
use Illuminate\Contracts\Container\Container;

use function assert;

class EntityManagerProvider implements DoctrineEntityManagerProvider
{
public function __construct(private ManagerRegistry $managerRegistry)
public function __construct(private Container $container)

Check warning on line 16 in src/Console/EntityManagerProvider.php

View check run for this annotation

Codecov / codecov/patch

src/Console/EntityManagerProvider.php#L16

Added line #L16 was not covered by tests
{
}

public function getDefaultManager(): EntityManagerInterface
{
$entityManager = $this->managerRegistry->getManager();
$entityManager = $this->container->make(ManagerRegistry::class)->getManager();

Check warning on line 22 in src/Console/EntityManagerProvider.php

View check run for this annotation

Codecov / codecov/patch

src/Console/EntityManagerProvider.php#L22

Added line #L22 was not covered by tests

assert($entityManager instanceof EntityManagerInterface);

Expand All @@ -27,7 +28,7 @@

public function getManager(string $name): EntityManagerInterface
{
$entityManager = $this->managerRegistry->getManager($name);
$entityManager = $this->container->make(ManagerRegistry::class)->getManager($name);

Check warning on line 31 in src/Console/EntityManagerProvider.php

View check run for this annotation

Codecov / codecov/patch

src/Console/EntityManagerProvider.php#L31

Added line #L31 was not covered by tests

assert($entityManager instanceof EntityManagerInterface);

Expand Down
Loading