1 | <?php |
||
26 | abstract class AbstractMessageBuilder |
||
27 | { |
||
28 | /** |
||
29 | * Fully qualified namespace of the custom message class |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $messageClass; |
||
34 | |||
35 | /** |
||
36 | * Fully qualified names of the message meta class |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $messageMetaClass; |
||
41 | |||
42 | /** |
||
43 | * Fully qualified name of the thread class |
||
44 | * |
||
45 | * @var string |
||
46 | */ |
||
47 | protected $threadClass; |
||
48 | |||
49 | /** |
||
50 | * Fully qualified name of the thread meta class |
||
51 | * |
||
52 | * @var string |
||
53 | */ |
||
54 | protected $threadMetaClass; |
||
55 | |||
56 | /** |
||
57 | * Sets the message class |
||
58 | * |
||
59 | * @param string $messageClass Fully qualified name of message class |
||
60 | */ |
||
61 | public function setMessageClass($messageClass) |
||
65 | |||
66 | /** |
||
67 | * Sets the message meta class |
||
68 | * |
||
69 | * @param string $messageMetaClass Fully qualified name the message meta class |
||
70 | */ |
||
71 | public function setMessageMetaClass($messageMetaClass) |
||
75 | |||
76 | /** |
||
77 | * Sets the thread class |
||
78 | * |
||
79 | * @param string $threadClass Fully qualified name of the thread class |
||
80 | */ |
||
81 | public function setThreadClass($threadClass) |
||
85 | |||
86 | /** |
||
87 | * Sets the thread meta class |
||
88 | * |
||
89 | * @param string $threadMetaClass Fully qualified name of the thread meta class |
||
90 | */ |
||
91 | public function setThreadMetaClass($threadMetaClass) |
||
95 | |||
96 | /** |
||
97 | * Builds a new message |
||
98 | * |
||
99 | * @param ThreadInterface $thread |
||
100 | */ |
||
101 | protected function buildNewMessage(ThreadInterface $thread) |
||
121 | |||
122 | /** |
||
123 | * Creates new message meta for the participant |
||
124 | * |
||
125 | * @param MessageInterface $message The message the meta belongs |
||
126 | * @param ParticipantInterface $participant The participant in the thread this message belongs to |
||
127 | * |
||
128 | * @return MessageMetaInterface |
||
129 | */ |
||
130 | private function createNewMessageMetaForParticipant(MessageInterface $message, ParticipantInterface $participant) |
||
146 | |||
147 | /** |
||
148 | * Updates the message with the message data in the builder model |
||
149 | * |
||
150 | * @param MessageInterface $message |
||
151 | */ |
||
152 | protected function setMessageData(MessageInterface $message) |
||
156 | |||
157 | /** |
||
158 | * Updates the message meta for the sender. |
||
159 | * |
||
160 | * It processes first the message meta for all participants |
||
161 | * Then it processes the message meta specific for the sender |
||
162 | * |
||
163 | * @param MessageMetaInterface $messageMeta |
||
164 | */ |
||
165 | protected function updateMessageMetaForSender(MessageMetaInterface $messageMeta) |
||
170 | |||
171 | /** |
||
172 | * Updates the message meta for the recipient. |
||
173 | * |
||
174 | * It processes first the message meta for all participants |
||
175 | * Then it processes the message meta specific for the recipient. |
||
176 | * |
||
177 | * @param MessageMetaInterface $messageMeta |
||
178 | */ |
||
179 | protected function updateMessageMetaForRecipient(MessageMetaInterface $messageMeta) |
||
187 | |||
188 | /** |
||
189 | * Updates the given object with the given methodName and argumentName |
||
190 | * |
||
191 | * @param string $callMethodName Calls the builder with this methodName |
||
192 | * @param string|null $callMethodArgument Calls the builder with this argument for the given methodName |
||
193 | * @param BuilderInterface $object The object which gets updated |
||
194 | */ |
||
195 | protected function processBuilderModel($callMethodName, $callMethodArgument, BuilderInterface $object) |
||
208 | |||
209 | /** |
||
210 | * Gets the setter method for the given key. |
||
211 | * |
||
212 | * This function tries to find the setter for the given key. By convention this should be setKey. |
||
213 | * |
||
214 | * It checks the object if there is a method which is named setKey and if that method is callable (is public) |
||
215 | * If not it throws an invalidArgumentException |
||
216 | * |
||
217 | * @param string $key |
||
218 | * @param object $object |
||
219 | * |
||
220 | * @return string The callable setter method |
||
221 | * |
||
222 | * @throws \InvalidArgumentException If no callable setter found |
||
223 | */ |
||
224 | protected function getSetter($key, $object) |
||
239 | |||
240 | /** |
||
241 | * creates a new message object |
||
242 | * |
||
243 | * @return MessageInterface |
||
244 | */ |
||
245 | private function createMessage() |
||
249 | |||
250 | /** |
||
251 | * creates a new message meta object |
||
252 | * |
||
253 | * @return MessageMetaInterface |
||
254 | */ |
||
255 | private function createMessageMeta() |
||
259 | |||
260 | /** |
||
261 | * Creates the message meta for a new message. |
||
262 | * |
||
263 | * @param MessageInterface $message |
||
264 | */ |
||
265 | private function createMessageMetaForNewMessage(MessageInterface $message) |
||
275 | |||
276 | /** |
||
277 | * Updates the thread meta with settings specific for the sender |
||
278 | * |
||
279 | * @param ThreadMetaInterface $threadMeta |
||
280 | */ |
||
281 | protected function updateThreadMetaForSender(ThreadMetaInterface $threadMeta) |
||
286 | |||
287 | /** |
||
288 | * Updates the thread meta with the settings specific for the recipient |
||
289 | * |
||
290 | * This processes the builder model |
||
291 | * |
||
292 | * @param ThreadMetaInterface $threadMeta |
||
293 | */ |
||
294 | protected function updateThreadMetaForRecipient(ThreadMetaInterface $threadMeta) |
||
301 | |||
302 | /** |
||
303 | * Increases the unread message count for the recipient. |
||
304 | * |
||
305 | * Since the recipient has received a new message we need to increase the unread message count for the recipient. |
||
306 | * When it's a new thread this count should become one. |
||
307 | * When it's a we should add +1 to the current unread count. |
||
308 | * |
||
309 | * @param ThreadMetaInterface $threadMeta |
||
310 | */ |
||
311 | protected function increaseUnreadMessageCountRecipient(ThreadMetaInterface $threadMeta) |
||
317 | |||
318 | /** |
||
319 | * If the recipient has marked his message as archived but receives a new message that message would not appear |
||
320 | * in his inbox folder. This feels wrong since now there is an unread message count in the archived box. |
||
321 | * |
||
322 | * Archived also means no longer active, but receiving a new reply makes it active again. So it makes sense to put |
||
323 | * this back in the inbox folder. |
||
324 | * |
||
325 | * To consider: using the thread status manager for this, since there is also an event bound to the thread status |
||
326 | * manager which we are not receiving now... |
||
327 | * |
||
328 | * @param ThreadMetaInterface $threadMeta |
||
329 | */ |
||
330 | protected function maybeUpdateThreadStatusForRecipient(ThreadMetaInterface $threadMeta) |
||
341 | } |
||
342 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: