1 | <?php |
||
10 | abstract class EntityManagedCachingEndpointFactory extends CachingEndpointFactory |
||
11 | { |
||
12 | /** |
||
13 | * @var EntityManager |
||
14 | */ |
||
15 | protected $entityManager; |
||
16 | |||
17 | 1 | public function __construct(EntityManager $entityManager, CacheItemPoolInterface $cachePool, LoggerInterface $logger) |
|
22 | |||
23 | 1 | protected function getCachingEndpoint(string $name, string $version): CachingEndpoint |
|
29 | |||
30 | protected abstract function getEntityManagedCachingEndpoint(string $name, string $version): EntityManagedCachingEndpoint; |
||
31 | } |
||
32 |
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.