1 | <?php |
||
13 | class ConfigureActionsMenuListener |
||
14 | { |
||
15 | /** |
||
16 | * @var EntityManager |
||
17 | */ |
||
18 | private $em; |
||
19 | |||
20 | /** |
||
21 | * @var Router |
||
22 | */ |
||
23 | private $router; |
||
24 | |||
25 | /** |
||
26 | * @param EntityManager $em The entity manager |
||
27 | * @param RouterInterface $router The router |
||
28 | */ |
||
29 | public function __construct(EntityManager $em, RouterInterface $router) |
||
34 | |||
35 | /** |
||
36 | * Configure the form submissions link on top of the form in the sub action menu |
||
37 | * |
||
38 | * @param ConfigureActionMenuEvent $event |
||
39 | */ |
||
40 | public function onSubActionMenuConfigure(ConfigureActionMenuEvent $event) |
||
53 | } |
||
54 |
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.