1 | <?php |
||
18 | class WebhookRepository implements WebhookRepositoryInterface |
||
19 | { |
||
20 | /** |
||
21 | * @var ObjectManager |
||
22 | */ |
||
23 | private $em; |
||
24 | |||
25 | /** |
||
26 | * MessageRepository constructor. |
||
27 | * |
||
28 | * @param EntityManager $em |
||
29 | */ |
||
30 | public function __construct(EntityManager $em) |
||
34 | |||
35 | /** |
||
36 | * @param $id |
||
37 | * |
||
38 | * @return null|object|Webhook |
||
39 | */ |
||
40 | public function get($id) |
||
44 | |||
45 | /** |
||
46 | * @param $reference |
||
47 | * |
||
48 | * @return null|object|Webhook |
||
49 | */ |
||
50 | public function getByReference($reference) |
||
60 | |||
61 | /** |
||
62 | * @param int $count |
||
63 | * |
||
64 | * @return Webhook[] |
||
65 | */ |
||
66 | public function getLastWebhooks(int $count): array |
||
74 | |||
75 | /** |
||
76 | * @param Webhook $webhook |
||
77 | */ |
||
78 | public function update(Webhook $webhook) |
||
82 | |||
83 | /** |
||
84 | * @param Webhook $webhook |
||
85 | */ |
||
86 | public function save(Webhook $webhook) |
||
91 | |||
92 | /** |
||
93 | * @param \DateTime $time |
||
94 | */ |
||
95 | public function clearOutdated(\DateTime $time) |
||
100 | } |
The
EntityManager
might 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
EntityManager
is closed. Any other code which depends on the same instance of theEntityManager
during 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.