1 | <?php |
||
16 | class DoctrineNotificationRepository extends EntityRepository implements NotificationRepository |
||
17 | { |
||
18 | /** |
||
19 | * @var bool |
||
20 | */ |
||
21 | private $isPrecocious; |
||
22 | |||
23 | /** |
||
24 | * {@inheritdoc} |
||
25 | * @param bool $isPrecocious |
||
26 | */ |
||
27 | 3 | public function __construct($em, ClassMetadata $class, bool $isPrecocious) |
|
28 | { |
||
29 | 3 | $this->isPrecocious = $isPrecocious; |
|
30 | 3 | parent::__construct($em, $class); |
|
31 | 3 | } |
|
32 | |||
33 | /** |
||
34 | * {@inheritdoc} |
||
35 | */ |
||
36 | 3 | public function add(Notification $notification, bool $precocious = false): void |
|
37 | { |
||
38 | 3 | $deduplicationKey = $notification->deduplicationKey(); |
|
39 | 3 | if (!is_null($deduplicationKey) && $this->hasNotificationOfDeduplicationKey($deduplicationKey)) { |
|
40 | 1 | throw new LogicException( |
|
41 | 1 | sprintf( |
|
42 | 1 | 'Notification of deduplication key (%s) already exists.', |
|
43 | 1 | $deduplicationKey |
|
44 | ) |
||
45 | ); |
||
46 | } |
||
47 | 3 | $this->persist($notification); |
|
48 | 3 | } |
|
49 | |||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | * @throws ORMException |
||
53 | * @throws OptimisticLockException |
||
54 | */ |
||
55 | 3 | public function persist(Notification $notification): void |
|
56 | { |
||
57 | 3 | $this->getEntityManager()->persist($notification); |
|
58 | 3 | if ($this->isPrecocious) { |
|
59 | 3 | $this->getEntityManager()->flush(); |
|
60 | } |
||
61 | 3 | } |
|
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | public function notificationOfId(NotificationId $notificationId): ?Notification |
||
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | 2 | public function hasNotificationOfDeduplicationKey(DeduplicationKey $deduplicationKey): bool |
|
78 | |||
79 | /** |
||
80 | * {@inheritdoc} |
||
81 | */ |
||
82 | 2 | public function freshNotifications(): array |
|
91 | } |
||
92 |