| 1 | <?php |
||
| 14 | class DoctrinePersistActionExecutor implements ActionExecutorInterface |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var EntityManager |
||
| 18 | */ |
||
| 19 | protected $entityManager; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @param EntityManager $entityManager |
||
| 23 | */ |
||
| 24 | 2 | public function __construct(EntityManager $entityManager) |
|
| 28 | |||
| 29 | /** |
||
| 30 | * @return EntityManager |
||
| 31 | */ |
||
| 32 | 1 | public function getEntityManager() : EntityManager |
|
| 36 | |||
| 37 | /** |
||
| 38 | * @inheritDoc |
||
| 39 | */ |
||
| 40 | 1 | public function execute(array $arguments) : array |
|
| 52 | |||
| 53 | /** |
||
| 54 | * @inheritDoc |
||
| 55 | */ |
||
| 56 | 1 | public static function getSupportedAction() : string |
|
| 60 | |||
| 61 | } |
||
| 62 |
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.