| 1 | <?php |
||
| 12 | class HistoryManagement implements HistoryManagementInterface |
||
| 13 | { |
||
| 14 | const ACTION_ADD = 'added'; |
||
| 15 | const ACTION_REMOVE = 'removed'; |
||
| 16 | const ACTION_UNKNOWN = 'unknown'; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var EntityManager |
||
| 20 | */ |
||
| 21 | private $entityManager; |
||
| 22 | |||
| 23 | public function __construct(EntityManager $entityManager) |
||
| 27 | |||
| 28 | public function fromPermission(Permission $permission): History |
||
| 52 | } |
||
| 53 |
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.