1 | <?php |
||
9 | class FeedbackManager { |
||
10 | /** @var EntityManager **/ |
||
11 | protected $em; |
||
12 | /** @var string **/ |
||
13 | protected $feedbackClass; |
||
14 | |||
15 | /** |
||
16 | * @param EntityManager $em |
||
17 | * @param string $feedbackClass |
||
18 | */ |
||
19 | public function __construct(EntityManager $em, $feedbackClass) { |
||
23 | |||
24 | /** |
||
25 | * @param ProjectModel $project |
||
26 | * @return array |
||
27 | */ |
||
28 | public function getProjectFeedbacks(ProjectModel $project) { |
||
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.