1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
<?php
declare(strict_types=1);
namespace Doctrine\Performance\Mock;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\UnitOfWork;
/**
* An unit of work mock that prevents lazy-loading of proxies
*/
class NonProxyLoadingUnitOfWork extends UnitOfWork
{
/** @var array<class-string, NonLoadingPersister> */
private array $entityPersisters = [];
public function __construct(
private EntityManagerInterface $entityManager,
) {
}
public function getEntityPersister(string $entityName): NonLoadingPersister
{
return $this->entityPersisters[$entityName]
??= new NonLoadingPersister($this->entityManager->getClassMetadata($entityName));
}
}
|