1 | <?php |
||
7 | class NotificationLog |
||
8 | { |
||
9 | |||
10 | /** |
||
11 | * @var \Doctrine\ORM\EntityManager |
||
12 | */ |
||
13 | private $em; |
||
14 | /** |
||
15 | * @var integer |
||
16 | */ |
||
17 | private $notificationDelayInHours; |
||
18 | |||
19 | public function __construct(EntityManager $em, $notificationDelayInHours) |
||
24 | |||
25 | /** |
||
26 | * Save NotificationLog |
||
27 | * |
||
28 | * @param \Monitor\Model\NotificationLog $notificationLog |
||
29 | */ |
||
30 | public function save(NotificationLogModel $notificationLog) |
||
35 | |||
36 | /** |
||
37 | * Get last fired up specific type of trigger for concret server |
||
38 | * |
||
39 | * @param int $triggerId |
||
40 | * @param int $serverId |
||
41 | */ |
||
42 | public function getLastForTrigger($triggerId, $serverId) |
||
61 | /** |
||
62 | * Check if same type of notification for concret server has been sent already |
||
63 | * |
||
64 | * @access private |
||
65 | * @param int $triggerId |
||
66 | * @param int $serverId |
||
67 | * @param int $msDelay |
||
68 | * @return boolean |
||
69 | */ |
||
70 | public function hasNotificationDelayExpired($triggerId, $serverId, $msDelay) |
||
83 | } |
||
84 |
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.