1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the WoW-Apps/Symfony-Slack-Bot bundle for Symfony. |
5
|
|
|
* https://github.com/wow-apps/symfony-slack-bot |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* https://github.com/wow-apps/symfony-slack-bot/blob/master/LICENSE |
10
|
|
|
* |
11
|
|
|
* For technical documentation. |
12
|
|
|
* https://wow-apps.github.io/symfony-slack-bot/docs/ |
13
|
|
|
* |
14
|
|
|
* Author Alexey Samara <[email protected]> |
15
|
|
|
* |
16
|
|
|
* Copyright 2016 WoW-Apps. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace WowApps\SlackBundle\Entity; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class Attachment. |
23
|
|
|
* |
24
|
|
|
* @author Alexey Samara <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class Attachment |
27
|
|
|
{ |
28
|
|
|
/** @var string */ |
29
|
|
|
private $color; |
30
|
|
|
|
31
|
|
|
/** @var string */ |
32
|
|
|
private $pretext; |
33
|
|
|
|
34
|
|
|
/** @var string */ |
35
|
|
|
private $authorName; |
36
|
|
|
|
37
|
|
|
/** @var string */ |
38
|
|
|
private $authorLink; |
39
|
|
|
|
40
|
|
|
/** @var string */ |
41
|
|
|
private $authorIconUrl; |
42
|
|
|
|
43
|
|
|
/** @var string */ |
44
|
|
|
private $title; |
45
|
|
|
|
46
|
|
|
/** @var string */ |
47
|
|
|
private $titleLink; |
48
|
|
|
|
49
|
|
|
/** @var string */ |
50
|
|
|
private $text; |
51
|
|
|
|
52
|
|
|
/** @var string */ |
53
|
|
|
private $imageUrl; |
54
|
|
|
|
55
|
|
|
/** @var string */ |
56
|
|
|
private $thumbUrl; |
57
|
|
|
|
58
|
|
|
/** @var string */ |
59
|
|
|
private $footer; |
60
|
|
|
|
61
|
|
|
/** @var string */ |
62
|
|
|
private $footerIconUrl; |
63
|
|
|
|
64
|
|
|
/** @var string */ |
65
|
|
|
private $fallback; |
66
|
|
|
|
67
|
|
|
/** @var int */ |
68
|
|
|
private $timestamp; |
69
|
|
|
|
70
|
|
|
/** @var AttachmentField[] */ |
71
|
|
|
private $fields; |
72
|
|
|
|
73
|
|
|
/** @var AttachmentAction[] */ |
74
|
|
|
private $actions; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* MessageAttachment constructor. |
78
|
|
|
* |
79
|
|
|
* @param string $color |
80
|
|
|
* @param string $pretext |
81
|
|
|
* @param string $authorName |
82
|
|
|
* @param string $authorLink |
83
|
|
|
* @param string $authorIconUrl |
84
|
|
|
* @param string $title |
85
|
|
|
* @param string $titleLink |
86
|
|
|
* @param string $text |
87
|
|
|
* @param string $imageUrl |
88
|
|
|
* @param string $thumbUrl |
89
|
|
|
* @param string $footer |
90
|
|
|
* @param string $footerIconUrl |
91
|
|
|
* @param string $fallback |
92
|
|
|
* @param int $timestamp |
93
|
|
|
* @param AttachmentField[] $fields |
94
|
|
|
* @param AttachmentAction[] $actions |
95
|
|
|
*/ |
96
|
|
|
public function __construct( |
97
|
|
|
string $color = '', |
98
|
|
|
string $pretext = '', |
99
|
|
|
string $authorName = '', |
100
|
|
|
string $authorLink = '', |
101
|
|
|
string $authorIconUrl = '', |
102
|
|
|
string $title = '', |
103
|
|
|
string $titleLink = '', |
104
|
|
|
string $text = '', |
105
|
|
|
string $imageUrl = '', |
106
|
|
|
string $thumbUrl = '', |
107
|
|
|
string $footer = '', |
108
|
|
|
string $footerIconUrl = '', |
109
|
|
|
string $fallback = '', |
110
|
|
|
int $timestamp = 0, |
111
|
|
|
array $fields = [], |
112
|
|
|
array $actions = [] |
113
|
|
|
) { |
114
|
|
|
$this->color = $color; |
115
|
|
|
$this->pretext = $pretext; |
116
|
|
|
$this->authorName = $authorName; |
117
|
|
|
$this->authorLink = $authorLink; |
118
|
|
|
$this->authorIconUrl = $authorIconUrl; |
119
|
|
|
$this->title = $title; |
120
|
|
|
$this->titleLink = $titleLink; |
121
|
|
|
$this->text = $text; |
122
|
|
|
$this->fields = $fields; |
123
|
|
|
$this->imageUrl = $imageUrl; |
124
|
|
|
$this->thumbUrl = $thumbUrl; |
125
|
|
|
$this->footer = $footer; |
126
|
|
|
$this->footerIconUrl = $footerIconUrl; |
127
|
|
|
$this->fallback = $fallback; |
128
|
|
|
$this->timestamp = $timestamp; |
129
|
|
|
$this->actions = $actions; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Returns attachment's left border color. |
134
|
|
|
* |
135
|
|
|
* @return string |
136
|
|
|
*/ |
137
|
|
|
public function getColor(): string |
138
|
|
|
{ |
139
|
|
|
return $this->color; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Set attachment’s left border color. |
144
|
|
|
* |
145
|
|
|
* @param string $color |
146
|
|
|
* |
147
|
|
|
* @return Attachment |
148
|
|
|
*/ |
149
|
|
|
public function setColor(string $color): Attachment |
150
|
|
|
{ |
151
|
|
|
$this->color = $color; |
152
|
|
|
|
153
|
|
|
return $this; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Returns text, that shown before attachment. |
158
|
|
|
* |
159
|
|
|
* @return string |
160
|
|
|
*/ |
161
|
|
|
public function getPretext(): string |
162
|
|
|
{ |
163
|
|
|
return $this->pretext; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Set the text, that shown before attachment. |
168
|
|
|
* |
169
|
|
|
* @param string $pretext |
170
|
|
|
* |
171
|
|
|
* @return Attachment |
172
|
|
|
*/ |
173
|
|
|
public function setPretext(string $pretext): Attachment |
174
|
|
|
{ |
175
|
|
|
$this->pretext = $pretext; |
176
|
|
|
|
177
|
|
|
return $this; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Returns name of the attachment's author. |
182
|
|
|
* |
183
|
|
|
* @return string |
184
|
|
|
*/ |
185
|
|
|
public function getAuthorName(): string |
186
|
|
|
{ |
187
|
|
|
return $this->authorName; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Set the attachment's author name. |
192
|
|
|
* |
193
|
|
|
* @param string $authorName |
194
|
|
|
* |
195
|
|
|
* @return Attachment |
196
|
|
|
*/ |
197
|
|
|
public function setAuthorName(string $authorName): Attachment |
198
|
|
|
{ |
199
|
|
|
$this->authorName = $authorName; |
200
|
|
|
|
201
|
|
|
return $this; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Returns attachment's author link. |
206
|
|
|
* |
207
|
|
|
* @return string |
208
|
|
|
*/ |
209
|
|
|
public function getAuthorLink(): string |
210
|
|
|
{ |
211
|
|
|
return $this->authorLink; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Set the attachment's author link. |
216
|
|
|
* |
217
|
|
|
* @param string $authorLink |
218
|
|
|
* |
219
|
|
|
* @return Attachment |
220
|
|
|
*/ |
221
|
|
|
public function setAuthorLink(string $authorLink): Attachment |
222
|
|
|
{ |
223
|
|
|
$this->authorLink = $authorLink; |
224
|
|
|
|
225
|
|
|
return $this; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Returns attachment's author icon url. |
230
|
|
|
* |
231
|
|
|
* @return string |
232
|
|
|
*/ |
233
|
|
|
public function getAuthorIconUrl(): string |
234
|
|
|
{ |
235
|
|
|
return $this->authorIconUrl; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* Set the attachment's author icon url. |
240
|
|
|
* |
241
|
|
|
* @param string $authorIconUrl |
242
|
|
|
* |
243
|
|
|
* @return Attachment |
244
|
|
|
*/ |
245
|
|
|
public function setAuthorIconUrl(string $authorIconUrl): Attachment |
246
|
|
|
{ |
247
|
|
|
$this->authorIconUrl = $authorIconUrl; |
248
|
|
|
|
249
|
|
|
return $this; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Returns attachment title. |
254
|
|
|
* |
255
|
|
|
* @return string |
256
|
|
|
*/ |
257
|
|
|
public function getTitle(): string |
258
|
|
|
{ |
259
|
|
|
return $this->title; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* Set attachment title. |
264
|
|
|
* |
265
|
|
|
* @param string $title |
266
|
|
|
* |
267
|
|
|
* @return Attachment |
268
|
|
|
*/ |
269
|
|
|
public function setTitle(string $title): Attachment |
270
|
|
|
{ |
271
|
|
|
$this->title = $title; |
272
|
|
|
|
273
|
|
|
return $this; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* Returns attachment title link. |
278
|
|
|
* |
279
|
|
|
* @return string |
280
|
|
|
*/ |
281
|
|
|
public function getTitleLink(): string |
282
|
|
|
{ |
283
|
|
|
return $this->titleLink; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* Set attachment title link. |
288
|
|
|
* |
289
|
|
|
* @param string $titleLink |
290
|
|
|
* |
291
|
|
|
* @return Attachment |
292
|
|
|
*/ |
293
|
|
|
public function setTitleLink(string $titleLink): Attachment |
294
|
|
|
{ |
295
|
|
|
$this->titleLink = $titleLink; |
296
|
|
|
|
297
|
|
|
return $this; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* Returns attachment main text. |
302
|
|
|
* |
303
|
|
|
* @return string |
304
|
|
|
*/ |
305
|
|
|
public function getText(): string |
306
|
|
|
{ |
307
|
|
|
return $this->text; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* Set attachment main text. |
312
|
|
|
* |
313
|
|
|
* @param string $text |
314
|
|
|
* |
315
|
|
|
* @return Attachment |
316
|
|
|
*/ |
317
|
|
|
public function setText(string $text): Attachment |
318
|
|
|
{ |
319
|
|
|
$this->text = $text; |
320
|
|
|
|
321
|
|
|
return $this; |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* Returns collection of attachment fields. |
326
|
|
|
* |
327
|
|
|
* @return AttachmentField[] |
328
|
|
|
*/ |
329
|
|
|
public function getFields(): array |
330
|
|
|
{ |
331
|
|
|
return $this->fields; |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* Set collection of attachment fields. |
336
|
|
|
* |
337
|
|
|
* @param AttachmentField[] $fields |
338
|
|
|
* |
339
|
|
|
* @return Attachment |
340
|
|
|
*/ |
341
|
|
|
public function setFields(array $fields): Attachment |
342
|
|
|
{ |
343
|
|
|
$this->fields = $fields; |
344
|
|
|
|
345
|
|
|
return $this; |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* Append attachment fields to collection. |
350
|
|
|
* |
351
|
|
|
* @param AttachmentField $field |
352
|
|
|
* |
353
|
|
|
* @return Attachment |
354
|
|
|
*/ |
355
|
|
|
public function appendField(AttachmentField $field): Attachment |
356
|
|
|
{ |
357
|
|
|
if (empty($this->fields)) { |
358
|
|
|
$this->fields = []; |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
$this->fields[] = $field; |
362
|
|
|
|
363
|
|
|
return $this; |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
/** |
367
|
|
|
* Returns attachment image url. |
368
|
|
|
* |
369
|
|
|
* @return string |
370
|
|
|
*/ |
371
|
|
|
public function getImageUrl(): string |
372
|
|
|
{ |
373
|
|
|
return $this->imageUrl; |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
/** |
377
|
|
|
* Set attachment image url. |
378
|
|
|
* |
379
|
|
|
* @param string $imageUrl |
380
|
|
|
* |
381
|
|
|
* @return Attachment |
382
|
|
|
*/ |
383
|
|
|
public function setImageUrl(string $imageUrl): Attachment |
384
|
|
|
{ |
385
|
|
|
$this->imageUrl = $imageUrl; |
386
|
|
|
|
387
|
|
|
return $this; |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
/** |
391
|
|
|
* Returns attachment image thumb url. |
392
|
|
|
* |
393
|
|
|
* @return string |
394
|
|
|
*/ |
395
|
|
|
public function getThumbUrl(): string |
396
|
|
|
{ |
397
|
|
|
return $this->thumbUrl; |
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
/** |
401
|
|
|
* Set attachment image url. |
402
|
|
|
* |
403
|
|
|
* @param string $thumbUrl |
404
|
|
|
* |
405
|
|
|
* @return Attachment |
406
|
|
|
*/ |
407
|
|
|
public function setThumbUrl(string $thumbUrl): Attachment |
408
|
|
|
{ |
409
|
|
|
$this->thumbUrl = $thumbUrl; |
410
|
|
|
|
411
|
|
|
return $this; |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
/** |
415
|
|
|
* Returns attachment footer text. |
416
|
|
|
* |
417
|
|
|
* @return string |
418
|
|
|
*/ |
419
|
|
|
public function getFooter(): string |
420
|
|
|
{ |
421
|
|
|
return $this->footer; |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
/** |
425
|
|
|
* Set attachment footer text. |
426
|
|
|
* |
427
|
|
|
* @param string $footer |
428
|
|
|
* |
429
|
|
|
* @return Attachment |
430
|
|
|
*/ |
431
|
|
|
public function setFooter(string $footer): Attachment |
432
|
|
|
{ |
433
|
|
|
$this->footer = $footer; |
434
|
|
|
|
435
|
|
|
return $this; |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
/** |
439
|
|
|
* Returns attachment footer icon url. |
440
|
|
|
* |
441
|
|
|
* @return string |
442
|
|
|
*/ |
443
|
|
|
public function getFooterIconUrl(): string |
444
|
|
|
{ |
445
|
|
|
return $this->footerIconUrl; |
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
/** |
449
|
|
|
* Set attachment footer icon url. |
450
|
|
|
* |
451
|
|
|
* @param string $footerIconUrl |
452
|
|
|
* |
453
|
|
|
* @return Attachment |
454
|
|
|
*/ |
455
|
|
|
public function setFooterIconUrl(string $footerIconUrl): Attachment |
456
|
|
|
{ |
457
|
|
|
$this->footerIconUrl = $footerIconUrl; |
458
|
|
|
|
459
|
|
|
return $this; |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
/** |
463
|
|
|
* Returns attachment fallback text. |
464
|
|
|
* |
465
|
|
|
* @return string |
466
|
|
|
*/ |
467
|
|
|
public function getFallback(): string |
468
|
|
|
{ |
469
|
|
|
return $this->fallback; |
470
|
|
|
} |
471
|
|
|
|
472
|
|
|
/** |
473
|
|
|
* Set attachment fallback text. |
474
|
|
|
* |
475
|
|
|
* @param string $fallback |
476
|
|
|
* |
477
|
|
|
* @return Attachment |
478
|
|
|
*/ |
479
|
|
|
public function setFallback(string $fallback): Attachment |
480
|
|
|
{ |
481
|
|
|
$this->fallback = $fallback; |
482
|
|
|
|
483
|
|
|
return $this; |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
/** |
487
|
|
|
* Returns attachment timestamp, placed in footer. |
488
|
|
|
* |
489
|
|
|
* @return int |
490
|
|
|
*/ |
491
|
|
|
public function getTimestamp(): int |
492
|
|
|
{ |
493
|
|
|
return $this->timestamp; |
494
|
|
|
} |
495
|
|
|
|
496
|
|
|
/** |
497
|
|
|
* Set attachment timestamp, placed in footer. |
498
|
|
|
* |
499
|
|
|
* @param int $timestamp |
500
|
|
|
* |
501
|
|
|
* @return Attachment |
502
|
|
|
*/ |
503
|
|
|
public function setTimestamp(int $timestamp = 0): Attachment |
504
|
|
|
{ |
505
|
|
|
$this->timestamp = empty($timestamp) ? time() : $timestamp; |
506
|
|
|
|
507
|
|
|
return $this; |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
/** |
511
|
|
|
* Returns array of attachment actions. |
512
|
|
|
* |
513
|
|
|
* @return AttachmentAction[] |
514
|
|
|
*/ |
515
|
|
|
public function getActions(): array |
516
|
|
|
{ |
517
|
|
|
return $this->actions; |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
/** |
521
|
|
|
* Set array of attachment actions. |
522
|
|
|
* |
523
|
|
|
* @param AttachmentAction[] $actions |
524
|
|
|
* |
525
|
|
|
* @return Attachment |
526
|
|
|
*/ |
527
|
|
|
public function setActions(array $actions): Attachment |
528
|
|
|
{ |
529
|
|
|
$this->actions = $actions; |
530
|
|
|
|
531
|
|
|
return $this; |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
/** |
535
|
|
|
* Append action to attachment. |
536
|
|
|
* |
537
|
|
|
* @param AttachmentAction $action |
538
|
|
|
* |
539
|
|
|
* @return Attachment |
540
|
|
|
*/ |
541
|
|
|
public function appendAction(AttachmentAction $action): Attachment |
542
|
|
|
{ |
543
|
|
|
if (empty($this->actions)) { |
544
|
|
|
$this->actions = []; |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
$this->actions[] = $action; |
548
|
|
|
|
549
|
|
|
return $this; |
550
|
|
|
} |
551
|
|
|
} |
552
|
|
|
|