1 | <?php |
||
17 | class Installer { |
||
18 | |||
19 | private $entityManager; |
||
20 | |||
21 | 6 | public function __construct( EntityManager $entityManager ) { |
|
24 | |||
25 | 6 | public function install() { |
|
28 | |||
29 | 6 | public function uninstall() { |
|
32 | |||
33 | 6 | private function getSchemaTool() { |
|
36 | |||
37 | 6 | private function getClassMetaData() { |
|
40 | |||
41 | } |
||
42 |
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.