| 1 | <?php |
||
| 12 | final class DatabaseLoader |
||
| 13 | { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var bool |
||
| 17 | */ |
||
| 18 | private $isDbSchemaPrepared = FALSE; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var Connection |
||
| 22 | */ |
||
| 23 | private $connection; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var EntityManager |
||
| 27 | */ |
||
| 28 | private $entityManager; |
||
| 29 | |||
| 30 | |||
| 31 | public function __construct(Connection $connection, EntityManager $entityManager) |
||
| 36 | |||
| 37 | |||
| 38 | public function prepareCategoryTableWithTwoItems() |
||
| 54 | |||
| 55 | } |
||
| 56 |
The
EntityManagermight 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
EntityManageris closed. Any other code which depends on the same instance of theEntityManagerduring 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.