| 1 | <?php |
||
| 17 | class WebhookRepository implements WebhookRepositoryInterface |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @var EntityManager |
||
| 21 | */ |
||
| 22 | private $em; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * MessageRepository constructor. |
||
| 26 | * |
||
| 27 | * @param EntityManager $em |
||
| 28 | */ |
||
| 29 | public function __construct(EntityManager $em) |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param $id |
||
| 36 | * |
||
| 37 | * @return null|object|Webhook |
||
| 38 | */ |
||
| 39 | public function get($id) |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @param int $count |
||
| 46 | * |
||
| 47 | * @return Webhook[] |
||
| 48 | */ |
||
| 49 | public function getLastWebhooks(int $count): array |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @param Webhook $webhook |
||
| 60 | */ |
||
| 61 | public function update(Webhook $webhook) |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @param Webhook $webhook |
||
| 68 | */ |
||
| 69 | public function save(Webhook $webhook) |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @param \DateTime $time |
||
| 77 | */ |
||
| 78 | public function clearOutdated(\DateTime $time) |
||
| 83 | } |
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.