1 | <?php |
||
19 | class InvalidateTokenAction implements MiddlewareInterface |
||
20 | { |
||
21 | /** |
||
22 | * @var EntityManager |
||
23 | */ |
||
24 | private $entityManager; |
||
25 | /** |
||
26 | * @var LoggerInterface |
||
27 | */ |
||
28 | private $logger; |
||
29 | /** |
||
30 | * @var HydratorInterface |
||
31 | */ |
||
32 | private $hydrator; |
||
33 | |||
34 | 1 | public function __construct(EntityManager $entityManager, LoggerInterface $logger, HydratorInterface $hydrator) |
|
40 | |||
41 | /** |
||
42 | * @inheritdoc |
||
43 | * @throws ORMException |
||
44 | */ |
||
45 | 1 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
61 | } |
||
62 |
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.