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 | * NotificationBuilder constructor. |
||
39 | */ |
||
40 | public function __construct() |
||
44 | |||
45 | /** |
||
46 | * @param PayloadHandlerInterface $handler |
||
47 | * @return $this |
||
48 | */ |
||
49 | public function addPayloadHandler(PayloadHandlerInterface $handler) |
||
59 | |||
60 | /** |
||
61 | * @return PayloadHandlerInterface[] |
||
62 | */ |
||
63 | public function getPayloadHandlers() |
||
67 | |||
68 | /** |
||
69 | * @return \ArrayIterator |
||
70 | */ |
||
71 | public function getNotificationCollection() |
||
75 | |||
76 | /** |
||
77 | * Generates number of notifications by message recipient count |
||
78 | * and notification service limitations |
||
79 | * |
||
80 | * @param MessageInterface $message |
||
81 | * @return $this |
||
82 | */ |
||
83 | public function buildNotifications(MessageInterface $message) |
||
110 | |||
111 | /** |
||
112 | * Returns created notification |
||
113 | * |
||
114 | * @param \ArrayIterator $recipients |
||
115 | * @return Notification |
||
116 | * @throws MalformedNotificationException |
||
117 | */ |
||
118 | private function createNotification(\ArrayIterator $recipients) |
||
147 | |||
148 | /** |
||
149 | * @param PayloadHandlerInterface $handler |
||
150 | * @param MessageInterface $message |
||
151 | * @return string |
||
152 | * @throws MalformedNotificationException |
||
153 | */ |
||
154 | private function handlePayload(PayloadHandlerInterface $handler, MessageInterface $message) |
||
165 | |||
166 | /** |
||
167 | * Check if maximum size allowed for a notification payload exceeded |
||
168 | * |
||
169 | * @param PayloadHandlerInterface $handler |
||
170 | * @param string $payload |
||
171 | * @throws MalformedNotificationException |
||
172 | */ |
||
173 | private function validatePayload(PayloadHandlerInterface $handler, $payload) |
||
190 | } |
||
191 |