File: NonProxyLoadingUnitOfWork.php

package info (click to toggle)
doctrine 3.6.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,924 kB
  • sloc: php: 110,871; xml: 1,410; makefile: 35
file content (28 lines) | stat: -rw-r--r-- 708 bytes parent folder | download | duplicates (2)
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));
    }
}