1 | <?php |
||
11 | class DoctrineORMPopulationFetcher implements PopulationFetcherInterface |
||
12 | { |
||
13 | const ROOT_ALIAS = 'e'; |
||
14 | |||
15 | /** |
||
16 | * @var EntityRepository |
||
17 | */ |
||
18 | protected $entityRepository; |
||
19 | |||
20 | /** |
||
21 | * @var ClassMetadata |
||
22 | */ |
||
23 | protected $entityClassMetadata; |
||
24 | |||
25 | /** |
||
26 | * @var EntityManager |
||
27 | */ |
||
28 | protected $entityManager; |
||
29 | |||
30 | /** |
||
31 | * @param EntityManager $entityManager |
||
32 | * @param string $entityName |
||
33 | */ |
||
34 | public function __construct(EntityManager $entityManager, $entityName) |
||
42 | |||
43 | /** |
||
44 | * @return QueryBuilder |
||
45 | */ |
||
46 | protected function createQueryBuilder() |
||
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | public function getEntityCount() |
||
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | public function fetchEntities($offset = 0, $limit = null) |
||
86 | } |
The
EntityManager
might become unusable for example if a transaction is rolled back and it gets closed. Let’s assume that somewhere in your application, or in a third-party library, there is code such as the following:If that code throws an exception and the
EntityManager
is closed. Any other code which depends on the same instance of theEntityManager
during this request will fail.On the other hand, if you instead inject the
ManagerRegistry
, thegetManager()
method guarantees that you will always get a usable manager instance.