Skip to content

Commit

Permalink
ManagerRegistry: support decorated EntityManager (#115)
Browse files Browse the repository at this point in the history
* FIX: ManagerRegistry correctly return decorated EntityManager
* CodingStandard fix
* Fix reseting decorated EntityManagers
  • Loading branch information
krekos authored Jan 10, 2025
1 parent 97d7f11 commit 6db8299
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/DI/Helpers/BuilderMan.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public function getManagersMap(): array
$definitions[$tagValue['name']] = $serviceName;
}

/** @var array{name: string} $tagValue */
foreach ($builder->findByTag(OrmExtension::MANAGER_DECORATOR_TAG) as $serviceName => $tagValue) {
$definitions[$tagValue['name']] = $serviceName;
}

return $definitions;
}

Expand Down
13 changes: 11 additions & 2 deletions src/ManagerRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Doctrine\ORM\EntityManager;
use Doctrine\Persistence\AbstractManagerRegistry;
use Doctrine\Persistence\ObjectManagerDecorator;
use Doctrine\Persistence\Proxy;
use Nette\DI\Container;
use Nettrine\ORM\Utils\Binder;
Expand Down Expand Up @@ -45,9 +46,17 @@ protected function resetService(string $name): void
$manager = $this->container->getService($name);

Binder::use($manager, function (): void {
/** @var EntityManager $this */
$this->closed = false; // @phpstan-ignore-line
if ($this instanceof EntityManager) { // @phpstan-ignore-line
$this->closed = false;
} elseif ($this instanceof ObjectManagerDecorator) { // @phpstan-ignore-line
Binder::use($this->wrapped, function (): void {
if ($this instanceof EntityManager) {// @phpstan-ignore-line
$this->closed = false;
}
});
}
});
//throw new \Exception($manager::class);

$this->container->removeService($name);
}
Expand Down

0 comments on commit 6db8299

Please sign in to comment.