1 | <?php |
||
20 | class NotificationBuilder |
||
21 | { |
||
22 | /** |
||
23 | * @var PayloadHandlerInterface[] |
||
24 | */ |
||
25 | private $payloadHandlers; |
||
26 | |||
27 | /** |
||
28 | * @var MessageInterface |
||
29 | */ |
||
30 | private $message; |
||
31 | |||
32 | /** |
||
33 | * @var \ArrayIterator |
||
34 | */ |
||
35 | private $notificationCollection; |
||
36 | |||
37 | /** |
||
38 | * @param PayloadHandlerInterface $handler |
||
39 | * @return $this |
||
40 | */ |
||
41 | public function addPayloadHandler(PayloadHandlerInterface $handler) |
||
51 | |||
52 | /** |
||
53 | * @return \ArrayIterator |
||
54 | */ |
||
55 | public function getNotificationCollection() |
||
59 | |||
60 | /** |
||
61 | * Generates number of notifications by message recipient count |
||
62 | * and notification service limitations |
||
63 | * |
||
64 | * @param MessageInterface $message |
||
65 | * @return $this |
||
66 | */ |
||
67 | public function buildNotifications(MessageInterface $message) |
||
94 | |||
95 | /** |
||
96 | * Returns created notification |
||
97 | * |
||
98 | * @param \ArrayIterator $recipients |
||
99 | * @return Notification |
||
100 | * @throws MalformedNotificationException |
||
101 | */ |
||
102 | private function createNotification(\ArrayIterator $recipients) |
||
129 | |||
130 | /** |
||
131 | * @param PayloadHandlerInterface $handler |
||
132 | * @param MessageInterface $message |
||
133 | * @return string |
||
134 | * @throws MalformedNotificationException |
||
135 | */ |
||
136 | private function handlePayload(PayloadHandlerInterface $handler, MessageInterface $message) |
||
147 | |||
148 | /** |
||
149 | * Check if maximum size allowed for a notification payload exceeded |
||
150 | * |
||
151 | * @param PayloadHandlerInterface $handler |
||
152 | * @param string $payload |
||
153 | * @throws MalformedNotificationException |
||
154 | */ |
||
155 | private function validatePayload(PayloadHandlerInterface $handler, $payload) |
||
172 | } |
||
173 |