| 1 | <?php |
||
| 10 | class DoctrineEntityManagerResetter implements ResetterInterface |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var EntityManager |
||
| 14 | */ |
||
| 15 | private $entityManager; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Constructor. |
||
| 19 | * |
||
| 20 | * @param EntityManager $entityManager |
||
| 21 | */ |
||
| 22 | 1 | public function __construct(EntityManager $entityManager) |
|
| 26 | |||
| 27 | /** |
||
| 28 | * {@inheritDoc} |
||
| 29 | */ |
||
| 30 | 1 | public function reset() |
|
| 40 | |||
| 41 | 1 | private function resetLogger($sqlLogger) |
|
| 54 | } |
||
| 55 |
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.