1 | <?php |
||
10 | class Attachment |
||
11 | { |
||
12 | const COLOR_GOOD = 'good'; |
||
13 | const COLOR_WARNING = 'warning'; |
||
14 | const COLOR_DANGER = 'danger'; |
||
15 | |||
16 | /** |
||
17 | * The fallback text to use for clients that don't support attachments. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $fallback; |
||
22 | |||
23 | /** |
||
24 | * Optional text that should appear within the attachment. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $text = ''; |
||
29 | |||
30 | /** |
||
31 | * Optional image that should appear within the attachment. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $imageUrl; |
||
36 | |||
37 | /** |
||
38 | * Optional thumbnail that should appear within the attachment. |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $thumbUrl; |
||
43 | |||
44 | /** |
||
45 | * Optional text that should appear above the formatted data. |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $preText; |
||
50 | |||
51 | /** |
||
52 | * Optional title for the attachment. |
||
53 | * |
||
54 | * @var string |
||
55 | */ |
||
56 | protected $title; |
||
57 | |||
58 | /** |
||
59 | * Optional title link for the attachment. |
||
60 | * |
||
61 | * @var string |
||
62 | */ |
||
63 | protected $titleLink; |
||
64 | |||
65 | /** |
||
66 | * Optional author name for the attachment. |
||
67 | * |
||
68 | * @var string |
||
69 | */ |
||
70 | protected $authorName; |
||
71 | |||
72 | /** |
||
73 | * Optional author link for the attachment. |
||
74 | * |
||
75 | * @var string |
||
76 | */ |
||
77 | protected $authorLink; |
||
78 | |||
79 | /** |
||
80 | * Optional author icon for the attachment. |
||
81 | * |
||
82 | * @var string |
||
83 | */ |
||
84 | protected $authorIcon; |
||
85 | |||
86 | /** |
||
87 | * The color to use for the attachment. |
||
88 | * |
||
89 | * @var string |
||
90 | */ |
||
91 | protected $color; |
||
92 | |||
93 | /** |
||
94 | * The text to use for the attachment footer. |
||
95 | * |
||
96 | * @var string |
||
97 | */ |
||
98 | protected $footer; |
||
99 | |||
100 | /** |
||
101 | * The icon to use for the attachment footer. |
||
102 | * |
||
103 | * @var string |
||
104 | */ |
||
105 | protected $footerIcon; |
||
106 | |||
107 | /** |
||
108 | * The timestamp to use for the attachment. |
||
109 | * |
||
110 | * @var \DateTime |
||
111 | */ |
||
112 | protected $timestamp; |
||
113 | |||
114 | /** |
||
115 | * The fields of the attachment. |
||
116 | * |
||
117 | * @var Collection |
||
118 | */ |
||
119 | protected $fields; |
||
120 | |||
121 | /** |
||
122 | * The actions of the attachment. |
||
123 | * |
||
124 | * @var Collection |
||
125 | */ |
||
126 | protected $actions; |
||
127 | |||
128 | public static function create() |
||
132 | |||
133 | public function __construct() |
||
138 | |||
139 | /** |
||
140 | * Set the fallback text. |
||
141 | * |
||
142 | * @param string $fallback |
||
143 | * |
||
144 | * @return $this |
||
145 | */ |
||
146 | public function setFallback(string $fallback) |
||
152 | |||
153 | /** |
||
154 | * Set the optional text to appear within the attachment. |
||
155 | * |
||
156 | * @param string $text |
||
157 | * |
||
158 | * @return $this |
||
159 | */ |
||
160 | public function setText($text) |
||
166 | |||
167 | /** |
||
168 | * Set the optional image to appear within the attachment. |
||
169 | * |
||
170 | * @param string $imageUrl |
||
171 | * |
||
172 | * @return $this |
||
173 | */ |
||
174 | public function setImageUrl(string $imageUrl) |
||
180 | |||
181 | /** |
||
182 | * Set the optional thumbnail to appear within the attachment. |
||
183 | * |
||
184 | * @param string $thumbUrl |
||
185 | * |
||
186 | * @return $this |
||
187 | */ |
||
188 | public function setThumbUrl(string $thumbUrl) |
||
194 | |||
195 | /** |
||
196 | * Set the text that should appear above the formatted data. |
||
197 | * |
||
198 | * @param string $preText |
||
199 | * |
||
200 | * @return $this |
||
201 | */ |
||
202 | public function setPreText(string $preText) |
||
208 | |||
209 | /** |
||
210 | * Set the color to use for the attachment. |
||
211 | * |
||
212 | * @param string $color |
||
213 | * |
||
214 | * @return $this |
||
215 | */ |
||
216 | public function setColor($color) |
||
222 | |||
223 | /** |
||
224 | * Set the footer text to use for the attachment. |
||
225 | * |
||
226 | * @param string $footer |
||
227 | * |
||
228 | * @return $this |
||
229 | */ |
||
230 | public function setFooter(string $footer) |
||
236 | |||
237 | /** |
||
238 | * Set the footer icon to use for the attachment. |
||
239 | * |
||
240 | * @param string $footerIcon |
||
241 | * |
||
242 | * @return $this |
||
243 | */ |
||
244 | public function setFooterIcon(string $footerIcon) |
||
250 | |||
251 | /** |
||
252 | * Set the timestamp to use for the attachment. |
||
253 | * |
||
254 | * @param \DateTime $timestamp |
||
255 | * |
||
256 | * @return $this |
||
257 | */ |
||
258 | public function setTimestamp(DateTime $timestamp) |
||
264 | |||
265 | /** |
||
266 | * Set the title to use for the attachment. |
||
267 | * |
||
268 | * @param string $title |
||
269 | * |
||
270 | * @return $this |
||
271 | */ |
||
272 | public function setTitle(string $title) |
||
278 | |||
279 | /** |
||
280 | * Set the title link to use for the attachment. |
||
281 | * |
||
282 | * @param string $titleLink |
||
283 | * |
||
284 | * @return $this |
||
285 | */ |
||
286 | public function setTitleLink(string $titleLink) |
||
292 | |||
293 | /** |
||
294 | * Set the author name to use for the attachment. |
||
295 | * |
||
296 | * @param string $authorName |
||
297 | * |
||
298 | * @return $this |
||
299 | */ |
||
300 | public function setAuthorName(string $authorName) |
||
306 | |||
307 | /** |
||
308 | * Set the auhtor link to use for the attachment. |
||
309 | * |
||
310 | * @param string $authorLink |
||
311 | * |
||
312 | * @return $this |
||
313 | */ |
||
314 | public function setAuthorLink(string $authorLink) |
||
320 | |||
321 | /** |
||
322 | * Set the author icon to use for the attachment. |
||
323 | * |
||
324 | * @param string $authorIcon |
||
325 | * |
||
326 | * @return $this |
||
327 | */ |
||
328 | public function setAuthorIcon(string $authorIcon) |
||
334 | |||
335 | /** |
||
336 | * Add a field to the attachment. |
||
337 | * |
||
338 | * @param \Spatie\SlashCommand\AttachmentField|array $field |
||
339 | * |
||
340 | * @return $this |
||
341 | * |
||
342 | * @throws \Spatie\SlashCommand\Exceptions\FieldCannotBeAdded |
||
343 | */ |
||
344 | public function addField($field) |
||
361 | |||
362 | /** |
||
363 | * Add the fields for the attachment. |
||
364 | * |
||
365 | * @param array $fields |
||
366 | * |
||
367 | * @return $this |
||
368 | */ |
||
369 | public function addFields(array $fields) |
||
382 | |||
383 | /** |
||
384 | * Set the fields for the attachment. |
||
385 | * |
||
386 | * @param array $fields |
||
387 | * |
||
388 | * @return $this |
||
389 | */ |
||
390 | public function setFields(array $fields) |
||
398 | |||
399 | /** |
||
400 | * Clear all fields for this attachment. |
||
401 | * |
||
402 | * @return $this |
||
403 | */ |
||
404 | public function clearFields() |
||
410 | |||
411 | /** |
||
412 | * @param \Spatie\SlashCommand\AttachmentAction|array $action |
||
413 | * |
||
414 | * @return $this |
||
415 | * @throws \Spatie\SlashCommand\Exceptions\ActionCannotBeAdded |
||
416 | */ |
||
417 | public function addAction($action) |
||
435 | |||
436 | /** |
||
437 | * Add the actions for the attachment. |
||
438 | * |
||
439 | * @param array $actions |
||
440 | * |
||
441 | * @return $this |
||
442 | */ |
||
443 | public function addActions(array $actions) |
||
451 | |||
452 | /** |
||
453 | * Set the actions for the attachment. |
||
454 | * |
||
455 | * @param array $actions |
||
456 | * |
||
457 | * @return $this |
||
458 | */ |
||
459 | public function setActions(array $actions) |
||
467 | |||
468 | /** |
||
469 | * Clear all actions for this attachment. |
||
470 | * |
||
471 | * @return $this |
||
472 | */ |
||
473 | public function clearActions() |
||
479 | |||
480 | /** |
||
481 | * Convert this attachment to its array representation. |
||
482 | * |
||
483 | * @return array |
||
484 | */ |
||
485 | public function toArray() |
||
510 | } |
||
511 |