1 | <?php |
||
23 | abstract class AbstractMessageBuilderModel |
||
24 | { |
||
25 | const SENDER = 'sender'; |
||
26 | const ALL = 'all'; |
||
27 | const RECIPIENTS = 'recipients'; |
||
28 | |||
29 | private static $group = [ |
||
30 | 'sender' => self::SENDER, |
||
31 | 'all' => self::ALL, |
||
32 | 'recipients' => self::RECIPIENTS |
||
33 | ]; |
||
34 | |||
35 | /** |
||
36 | * @var NewMessageInterface |
||
37 | */ |
||
38 | protected $messageModel; |
||
39 | |||
40 | /** |
||
41 | * The array where we'll save all the data to |
||
42 | * |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $data = []; |
||
46 | |||
47 | /** |
||
48 | * Constructor. |
||
49 | * |
||
50 | * @param NewMessageInterface $messageModel |
||
51 | */ |
||
52 | public function __construct(NewMessageInterface $messageModel) |
||
57 | |||
58 | /** |
||
59 | * This processes the default message data. |
||
60 | * |
||
61 | * This method is called in the constructor and populates the default new message data. |
||
62 | * It also calls a method process extra which classes who extend this class have to implement. |
||
63 | * |
||
64 | * There we process some more default data. See the threadbuildermodel for an example. |
||
65 | * |
||
66 | * If you want to overwrite this data (not recommended!!) you can call the same method with the same key. |
||
67 | * This will overwrite that data in the array with your given value. |
||
68 | */ |
||
69 | protected function processDefaultMessageData() |
||
83 | |||
84 | /** |
||
85 | * Gets the sender of the message |
||
86 | * |
||
87 | * @return ParticipantInterface |
||
88 | */ |
||
89 | public function getSender() |
||
93 | |||
94 | /** |
||
95 | * Add message data to your message class. |
||
96 | * |
||
97 | * @param string $key The name of your classes attribute, example ip => builder will call setIp |
||
98 | * @param mixed $value The value of the attribute you want to set |
||
99 | */ |
||
100 | public function addMessageData($key, $value) |
||
104 | |||
105 | /** |
||
106 | * Returns the message data. |
||
107 | * |
||
108 | * The key is the attribute name and the value is the value. |
||
109 | * Example data['subject' => 'The subject of the message, 'createdAt' => \Datetime object] |
||
110 | * |
||
111 | * @return array An array with message data needed to populate the message class. |
||
112 | */ |
||
113 | public function getMessageData() |
||
117 | |||
118 | /** |
||
119 | * Add thread data to your thread class. |
||
120 | * |
||
121 | * @param string $key The name of your thread class attribute |
||
122 | * @param mixed $value The value for your attribute |
||
123 | */ |
||
124 | public function addThreadData($key, $value) |
||
128 | |||
129 | /** |
||
130 | * Gets the data for the thread class. |
||
131 | * |
||
132 | * This function is used by the builders to populate the thread object. |
||
133 | * |
||
134 | * @return array||null An array where the keys are the names of the attributes and the values the attribute values |
||
|
|||
135 | */ |
||
136 | public function getThreadData() |
||
140 | |||
141 | /** |
||
142 | * Adds message meta for a given participant group to your message meta class. |
||
143 | * |
||
144 | * @param string $participant One of the class constants SENDER ALL RECIPIENTS |
||
145 | * @param string $key The name of your message meta class attribute you want to add data for. |
||
146 | * @param mixed $value The value for your attribute |
||
147 | */ |
||
148 | public function addMessageMeta($participant, $key, $value) |
||
152 | |||
153 | /** |
||
154 | * Returns the message meta for the given group of participants. |
||
155 | * |
||
156 | * @param string $participant One of the class constants SENDER ALL RECIPIENTS |
||
157 | * |
||
158 | * @return array||null An array where the keys are the names of the attributes and the values the attribute values |
||
159 | */ |
||
160 | public function getMessageMeta($participant) |
||
164 | |||
165 | /** |
||
166 | * Adds thread meta for a given participant group to the thread meta class. |
||
167 | * |
||
168 | * @param string $participant One of the class constants SENDER ALL RECIPIENTS |
||
169 | * @param string $key The name of your thread meta class attribute |
||
170 | * @param mixed $value The value of your thread meta class attribute |
||
171 | */ |
||
172 | public function addThreadMeta($participant, $key, $value) |
||
176 | |||
177 | /** |
||
178 | * Returns the thread meta for the given group of participants. |
||
179 | * |
||
180 | * @param string $participant One of the class constants SENDER ALL RECIPIENTS |
||
181 | * |
||
182 | * @return array||null An array where the keys are the names of the attributes and the values the attribute values |
||
183 | */ |
||
184 | public function getThreadMeta($participant) |
||
188 | |||
189 | /** |
||
190 | * Returns the form model used to set the default data. |
||
191 | * |
||
192 | * If you added more data to the form model you can ask for the model and update the data in the processors. |
||
193 | */ |
||
194 | public function getFormModel() |
||
198 | |||
199 | /** |
||
200 | * Helper function to populate the data array. |
||
201 | * |
||
202 | * @param string $name Name of the meta one of threadMeta, messageMeta |
||
203 | * @param string $participant One of the class constants SENDER ALL RECIPIENTS |
||
204 | * @param string $key The name of the class attribute |
||
205 | * @param mixed $value The value of the class attribute |
||
206 | */ |
||
207 | protected function addMeta($name, $participant, $key, $value) |
||
211 | |||
212 | /** |
||
213 | * Helper function to get meta. |
||
214 | * |
||
215 | * @param string $name Name of the meta one of threadMeta, messageMeta |
||
216 | * @param string $participant One of the class constants SENDER ALL RECIPIENTS |
||
217 | * |
||
218 | * @return array||null An array where the keys are the names of the attributes and the values the attribute values |
||
219 | */ |
||
220 | protected function getMeta($name, $participant) |
||
225 | |||
226 | /** |
||
227 | * Helper function to add data to the array. |
||
228 | * |
||
229 | * @param string $name One of message, thread |
||
230 | * @param string $key Name of the attribute for the given class |
||
231 | * @param mixed $value Value for that attribute |
||
232 | */ |
||
233 | protected function addData($name, $key, $value) |
||
237 | |||
238 | /** |
||
239 | * Helper function to get data from the array. |
||
240 | * |
||
241 | * @param string $name One of message, thread |
||
242 | * |
||
243 | * @return array||null An array where the keys are the names of the attributes and the values the attribute values |
||
244 | */ |
||
245 | protected function getData($name) |
||
249 | |||
250 | /** |
||
251 | * Processes more default data specific to a new thread or a new reply. * |
||
252 | */ |
||
253 | abstract protected function processExtra(); |
||
254 | } |
||
255 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.