This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Maknz\Slack; |
||
4 | |||
5 | use InvalidArgumentException; |
||
6 | |||
7 | class Attachment |
||
8 | { |
||
9 | /** |
||
10 | * The fallback text to use for clients that don't support attachments. |
||
11 | * |
||
12 | * @var string |
||
13 | */ |
||
14 | protected $fallback; |
||
15 | |||
16 | /** |
||
17 | * Optional text that should appear within the attachment. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $text; |
||
22 | |||
23 | /** |
||
24 | * Optional image that should appear within the attachment. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $image_url; |
||
29 | |||
30 | /** |
||
31 | * Optional thumbnail that should appear within the attachment. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $thumb_url; |
||
36 | |||
37 | /** |
||
38 | * Optional text that should appear above the formatted data. |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $pretext; |
||
43 | |||
44 | /** |
||
45 | * Optional title for the attachment. |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $title; |
||
50 | |||
51 | /** |
||
52 | * Optional title link for the attachment. |
||
53 | * |
||
54 | * @var string |
||
55 | */ |
||
56 | protected $title_link; |
||
57 | |||
58 | /** |
||
59 | * Optional author name for the attachment. |
||
60 | * |
||
61 | * @var string |
||
62 | */ |
||
63 | protected $author_name; |
||
64 | |||
65 | /** |
||
66 | * Optional author link for the attachment. |
||
67 | * |
||
68 | * @var string |
||
69 | */ |
||
70 | protected $author_link; |
||
71 | |||
72 | /** |
||
73 | * Optional author icon for the attachment. |
||
74 | * |
||
75 | * @var string |
||
76 | */ |
||
77 | protected $author_icon; |
||
78 | |||
79 | /** |
||
80 | * The color to use for the attachment. |
||
81 | * |
||
82 | * @var string |
||
83 | */ |
||
84 | protected $color = 'good'; |
||
85 | |||
86 | /** |
||
87 | * The text to use for the attachment footer. |
||
88 | * |
||
89 | * @var string |
||
90 | */ |
||
91 | protected $footer; |
||
92 | |||
93 | /** |
||
94 | * The icon to use for the attachment footer. |
||
95 | * |
||
96 | * @var string |
||
97 | */ |
||
98 | protected $footer_icon; |
||
99 | |||
100 | /** |
||
101 | * The timestamp to use for the attachment. |
||
102 | * |
||
103 | * @var \DateTime |
||
104 | */ |
||
105 | protected $timestamp; |
||
106 | |||
107 | /** |
||
108 | * The fields of the attachment. |
||
109 | * |
||
110 | * @var array |
||
111 | */ |
||
112 | protected $fields = []; |
||
113 | |||
114 | /** |
||
115 | * The fields of the attachment that Slack should interpret |
||
116 | * with its Markdown-like language. |
||
117 | * |
||
118 | * @var array |
||
119 | */ |
||
120 | protected $markdown_fields = []; |
||
121 | |||
122 | /** |
||
123 | * A collection of actions (buttons) to include in the attachment. |
||
124 | * A maximum of 5 actions may be provided. |
||
125 | * |
||
126 | * @var array |
||
127 | */ |
||
128 | protected $actions = []; |
||
129 | |||
130 | /** |
||
131 | * Instantiate a new Attachment. |
||
132 | * |
||
133 | * @param array $attributes |
||
134 | * @return void |
||
0 ignored issues
–
show
|
|||
135 | */ |
||
136 | public function __construct(array $attributes) |
||
137 | { |
||
138 | if (isset($attributes['fallback'])) { |
||
139 | $this->setFallback($attributes['fallback']); |
||
140 | } |
||
141 | |||
142 | if (isset($attributes['text'])) { |
||
143 | $this->setText($attributes['text']); |
||
144 | } |
||
145 | |||
146 | if (isset($attributes['image_url'])) { |
||
147 | $this->setImageUrl($attributes['image_url']); |
||
148 | } |
||
149 | |||
150 | if (isset($attributes['thumb_url'])) { |
||
151 | $this->setThumbUrl($attributes['thumb_url']); |
||
152 | } |
||
153 | |||
154 | if (isset($attributes['pretext'])) { |
||
155 | $this->setPretext($attributes['pretext']); |
||
156 | } |
||
157 | |||
158 | if (isset($attributes['color'])) { |
||
159 | $this->setColor($attributes['color']); |
||
160 | } |
||
161 | |||
162 | if (isset($attributes['footer'])) { |
||
163 | $this->setFooter($attributes['footer']); |
||
164 | } |
||
165 | |||
166 | if (isset($attributes['footer_icon'])) { |
||
167 | $this->setFooterIcon($attributes['footer_icon']); |
||
168 | } |
||
169 | |||
170 | if (isset($attributes['timestamp'])) { |
||
171 | $this->setTimestamp($attributes['timestamp']); |
||
172 | } |
||
173 | |||
174 | if (isset($attributes['fields'])) { |
||
175 | $this->setFields($attributes['fields']); |
||
176 | } |
||
177 | |||
178 | if (isset($attributes['mrkdwn_in'])) { |
||
179 | $this->setMarkdownFields($attributes['mrkdwn_in']); |
||
180 | } |
||
181 | |||
182 | if (isset($attributes['title'])) { |
||
183 | $this->setTitle($attributes['title']); |
||
184 | } |
||
185 | |||
186 | if (isset($attributes['title_link'])) { |
||
187 | $this->setTitleLink($attributes['title_link']); |
||
188 | } |
||
189 | |||
190 | if (isset($attributes['author_name'])) { |
||
191 | $this->setAuthorName($attributes['author_name']); |
||
192 | } |
||
193 | |||
194 | if (isset($attributes['author_link'])) { |
||
195 | $this->setAuthorLink($attributes['author_link']); |
||
196 | } |
||
197 | |||
198 | if (isset($attributes['author_icon'])) { |
||
199 | $this->setAuthorIcon($attributes['author_icon']); |
||
200 | } |
||
201 | |||
202 | if (isset($attributes['actions'])) { |
||
203 | $this->setActions($attributes['actions']); |
||
204 | } |
||
205 | } |
||
206 | |||
207 | /** |
||
208 | * Get the fallback text. |
||
209 | * |
||
210 | * @return string |
||
211 | */ |
||
212 | public function getFallback() |
||
213 | { |
||
214 | return $this->fallback; |
||
215 | } |
||
216 | |||
217 | /** |
||
218 | * Set the fallback text. |
||
219 | * |
||
220 | * @param string $fallback |
||
221 | * @return $this |
||
222 | */ |
||
223 | public function setFallback($fallback) |
||
224 | { |
||
225 | $this->fallback = $fallback; |
||
226 | |||
227 | return $this; |
||
228 | } |
||
229 | |||
230 | /** |
||
231 | * Get the optional text to appear within the attachment. |
||
232 | * |
||
233 | * @return string |
||
234 | */ |
||
235 | public function getText() |
||
236 | { |
||
237 | return $this->text; |
||
238 | } |
||
239 | |||
240 | /** |
||
241 | * Set the optional text to appear within the attachment. |
||
242 | * |
||
243 | * @param string $text |
||
244 | * @return $this |
||
245 | */ |
||
246 | public function setText($text) |
||
247 | { |
||
248 | $this->text = $text; |
||
249 | |||
250 | return $this; |
||
251 | } |
||
252 | |||
253 | /** |
||
254 | * Get the optional image to appear within the attachment. |
||
255 | * |
||
256 | * @return string |
||
257 | */ |
||
258 | public function getImageUrl() |
||
259 | { |
||
260 | return $this->image_url; |
||
261 | } |
||
262 | |||
263 | /** |
||
264 | * Set the optional image to appear within the attachment. |
||
265 | * |
||
266 | * @param string $image_url |
||
267 | * @return $this |
||
268 | */ |
||
269 | public function setImageUrl($image_url) |
||
270 | { |
||
271 | $this->image_url = $image_url; |
||
272 | |||
273 | return $this; |
||
274 | } |
||
275 | |||
276 | /** |
||
277 | * Get the optional thumbnail to appear within the attachment. |
||
278 | * |
||
279 | * @return string |
||
280 | */ |
||
281 | public function getThumbUrl() |
||
282 | { |
||
283 | return $this->thumb_url; |
||
284 | } |
||
285 | |||
286 | /** |
||
287 | * Set the optional thumbnail to appear within the attachment. |
||
288 | * |
||
289 | * @param string $thumb_url |
||
290 | * @return $this |
||
291 | */ |
||
292 | public function setThumbUrl($thumb_url) |
||
293 | { |
||
294 | $this->thumb_url = $thumb_url; |
||
295 | |||
296 | return $this; |
||
297 | } |
||
298 | |||
299 | /** |
||
300 | * Get the text that should appear above the formatted data. |
||
301 | * |
||
302 | * @return string |
||
303 | */ |
||
304 | public function getPretext() |
||
305 | { |
||
306 | return $this->pretext; |
||
307 | } |
||
308 | |||
309 | /** |
||
310 | * Set the text that should appear above the formatted data. |
||
311 | * |
||
312 | * @param string $pretext |
||
313 | * @return $this |
||
314 | */ |
||
315 | public function setPretext($pretext) |
||
316 | { |
||
317 | $this->pretext = $pretext; |
||
318 | |||
319 | return $this; |
||
320 | } |
||
321 | |||
322 | /** |
||
323 | * Get the color to use for the attachment. |
||
324 | * |
||
325 | * @return string |
||
326 | */ |
||
327 | public function getColor() |
||
328 | { |
||
329 | return $this->color; |
||
330 | } |
||
331 | |||
332 | /** |
||
333 | * Set the color to use for the attachment. |
||
334 | * |
||
335 | * @param string $color |
||
336 | * @return $this |
||
337 | */ |
||
338 | public function setColor($color) |
||
339 | { |
||
340 | $this->color = $color; |
||
341 | |||
342 | return $this; |
||
343 | } |
||
344 | |||
345 | /** |
||
346 | * Get the footer to use for the attachment. |
||
347 | * |
||
348 | * @return string |
||
349 | */ |
||
350 | public function getFooter() |
||
351 | { |
||
352 | return $this->footer; |
||
353 | } |
||
354 | |||
355 | /** |
||
356 | * Set the footer text to use for the attachment. |
||
357 | * |
||
358 | * @param string $footer |
||
359 | * @return $this |
||
360 | */ |
||
361 | public function setFooter($footer) |
||
362 | { |
||
363 | $this->footer = $footer; |
||
364 | |||
365 | return $this; |
||
366 | } |
||
367 | |||
368 | /** |
||
369 | * Get the footer icon to use for the attachment. |
||
370 | * |
||
371 | * @return string |
||
372 | */ |
||
373 | public function getFooterIcon() |
||
374 | { |
||
375 | return $this->footer_icon; |
||
376 | } |
||
377 | |||
378 | /** |
||
379 | * Set the footer icon to use for the attachment. |
||
380 | * |
||
381 | * @param string $footerIcon |
||
382 | * @return $this |
||
383 | */ |
||
384 | public function setFooterIcon($footerIcon) |
||
385 | { |
||
386 | $this->footer_icon = $footerIcon; |
||
387 | |||
388 | return $this; |
||
389 | } |
||
390 | |||
391 | /** |
||
392 | * Get the timestamp to use for the attachment. |
||
393 | * |
||
394 | * @return \DateTime |
||
395 | */ |
||
396 | public function getTimestamp() |
||
397 | { |
||
398 | return $this->timestamp; |
||
399 | } |
||
400 | |||
401 | /** |
||
402 | * Set the timestamp to use for the attachment. |
||
403 | * |
||
404 | * @param \DateTime $timestamp |
||
405 | * @return $this |
||
406 | */ |
||
407 | public function setTimestamp($timestamp) |
||
408 | { |
||
409 | $this->timestamp = $timestamp; |
||
410 | |||
411 | return $this; |
||
412 | } |
||
413 | |||
414 | /** |
||
415 | * Get the title to use for the attachment. |
||
416 | * |
||
417 | * @return string |
||
418 | */ |
||
419 | public function getTitle() |
||
420 | { |
||
421 | return $this->title; |
||
422 | } |
||
423 | |||
424 | /** |
||
425 | * Set the title to use for the attachment. |
||
426 | * |
||
427 | * @param string $title |
||
428 | * @return $this |
||
429 | */ |
||
430 | public function setTitle($title) |
||
431 | { |
||
432 | $this->title = $title; |
||
433 | |||
434 | return $this; |
||
435 | } |
||
436 | |||
437 | /** |
||
438 | * Get the title link to use for the attachment. |
||
439 | * |
||
440 | * @return string |
||
441 | */ |
||
442 | public function getTitleLink() |
||
443 | { |
||
444 | return $this->title_link; |
||
445 | } |
||
446 | |||
447 | /** |
||
448 | * Set the title link to use for the attachment. |
||
449 | * |
||
450 | * @param string $title_link |
||
451 | * @return $this |
||
452 | */ |
||
453 | public function setTitleLink($title_link) |
||
454 | { |
||
455 | $this->title_link = $title_link; |
||
456 | |||
457 | return $this; |
||
458 | } |
||
459 | |||
460 | /** |
||
461 | * Get the author name to use for the attachment. |
||
462 | * |
||
463 | * @return string |
||
464 | */ |
||
465 | public function getAuthorName() |
||
466 | { |
||
467 | return $this->author_name; |
||
468 | } |
||
469 | |||
470 | /** |
||
471 | * Set the author name to use for the attachment. |
||
472 | * |
||
473 | * @param string $author_name |
||
474 | * @return $this |
||
475 | */ |
||
476 | public function setAuthorName($author_name) |
||
477 | { |
||
478 | $this->author_name = $author_name; |
||
479 | |||
480 | return $this; |
||
481 | } |
||
482 | |||
483 | /** |
||
484 | * Get the author link to use for the attachment. |
||
485 | * |
||
486 | * @return string |
||
487 | */ |
||
488 | public function getAuthorLink() |
||
489 | { |
||
490 | return $this->author_link; |
||
491 | } |
||
492 | |||
493 | /** |
||
494 | * Set the auhtor link to use for the attachment. |
||
495 | * |
||
496 | * @param string $author_link |
||
497 | * @return $this |
||
498 | */ |
||
499 | public function setAuthorLink($author_link) |
||
500 | { |
||
501 | $this->author_link = $author_link; |
||
502 | |||
503 | return $this; |
||
504 | } |
||
505 | |||
506 | /** |
||
507 | * Get the author icon to use for the attachment. |
||
508 | * |
||
509 | * @return string |
||
510 | */ |
||
511 | public function getAuthorIcon() |
||
512 | { |
||
513 | return $this->author_icon; |
||
514 | } |
||
515 | |||
516 | /** |
||
517 | * Set the author icon to use for the attachment. |
||
518 | * |
||
519 | * @param string $author_icon |
||
520 | * @return $this |
||
521 | */ |
||
522 | public function setAuthorIcon($author_icon) |
||
523 | { |
||
524 | $this->author_icon = $author_icon; |
||
525 | |||
526 | return $this; |
||
527 | } |
||
528 | |||
529 | /** |
||
530 | * Get the fields for the attachment. |
||
531 | * |
||
532 | * @return array |
||
533 | */ |
||
534 | public function getFields() |
||
535 | { |
||
536 | return $this->fields; |
||
537 | } |
||
538 | |||
539 | /** |
||
540 | * Set the fields for the attachment. |
||
541 | * |
||
542 | * @param array $fields |
||
543 | * @return $this |
||
544 | */ |
||
545 | public function setFields(array $fields) |
||
546 | { |
||
547 | $this->clearFields(); |
||
548 | |||
549 | foreach ($fields as $field) { |
||
550 | $this->addField($field); |
||
551 | } |
||
552 | |||
553 | return $this; |
||
554 | } |
||
555 | |||
556 | /** |
||
557 | * Add a field to the attachment. |
||
558 | * |
||
559 | * @param mixed $field |
||
560 | * @return $this |
||
561 | */ |
||
562 | public function addField($field) |
||
563 | { |
||
564 | if ($field instanceof AttachmentField) { |
||
565 | $this->fields[] = $field; |
||
566 | |||
567 | return $this; |
||
568 | } elseif (is_array($field)) { |
||
569 | $this->fields[] = new AttachmentField($field); |
||
570 | |||
571 | return $this; |
||
572 | } |
||
573 | |||
574 | throw new InvalidArgumentException('The attachment field must be an instance of Maknz\Slack\AttachmentField or a keyed array'); |
||
575 | } |
||
576 | |||
577 | /** |
||
578 | * Clear the fields for the attachment. |
||
579 | * |
||
580 | * @return $this |
||
581 | */ |
||
582 | public function clearFields() |
||
583 | { |
||
584 | $this->fields = []; |
||
585 | |||
586 | return $this; |
||
587 | } |
||
588 | |||
589 | /** |
||
590 | * Clear the actions for the attachment. |
||
591 | * |
||
592 | * @return $this |
||
593 | */ |
||
594 | public function clearActions() |
||
595 | { |
||
596 | $this->actions = []; |
||
597 | |||
598 | return $this; |
||
599 | } |
||
600 | |||
601 | /** |
||
602 | * Get the fields Slack should interpret in its |
||
603 | * Markdown-like language. |
||
604 | * |
||
605 | * @return array |
||
606 | */ |
||
607 | public function getMarkdownFields() |
||
608 | { |
||
609 | return $this->markdown_fields; |
||
610 | } |
||
611 | |||
612 | /** |
||
613 | * Set the fields Slack should interpret in its |
||
614 | * Markdown-like language. |
||
615 | * |
||
616 | * @param array $fields |
||
617 | * @return $this |
||
618 | */ |
||
619 | public function setMarkdownFields(array $fields) |
||
620 | { |
||
621 | $this->markdown_fields = $fields; |
||
622 | |||
623 | return $this; |
||
624 | } |
||
625 | |||
626 | /** |
||
627 | * Get the collection of actions (buttons) to include in the attachment. |
||
628 | * |
||
629 | * @return AttachmentAction[] |
||
630 | */ |
||
631 | public function getActions() |
||
632 | { |
||
633 | return $this->actions; |
||
634 | } |
||
635 | |||
636 | /** |
||
637 | * Set the collection of actions (buttons) to include in the attachment. |
||
638 | * |
||
639 | * @param array $actions |
||
640 | * @return Attachment |
||
641 | */ |
||
642 | public function setActions($actions) |
||
643 | { |
||
644 | $this->clearActions(); |
||
645 | |||
646 | foreach ($actions as $action) { |
||
647 | $this->addAction($action); |
||
648 | } |
||
649 | |||
650 | return $this; |
||
651 | } |
||
652 | |||
653 | /** |
||
654 | * Add an action to the attachment. |
||
655 | * |
||
656 | * @param mixed $action |
||
657 | * @return $this |
||
658 | */ |
||
659 | public function addAction($action) |
||
660 | { |
||
661 | if ($action instanceof AttachmentAction) { |
||
662 | $this->actions[] = $action; |
||
663 | |||
664 | return $this; |
||
665 | } elseif (is_array($action)) { |
||
666 | $this->actions[] = new AttachmentAction($action); |
||
667 | |||
668 | return $this; |
||
669 | } |
||
670 | |||
671 | throw new InvalidArgumentException('The attachment action must be an instance of Maknz\Slack\AttachmentAction or a keyed array'); |
||
672 | } |
||
673 | |||
674 | /** |
||
675 | * Convert this attachment to its array representation. |
||
676 | * |
||
677 | * @return array |
||
678 | */ |
||
679 | public function toArray() |
||
680 | { |
||
681 | $data = [ |
||
682 | 'fallback' => $this->getFallback(), |
||
683 | 'text' => $this->getText(), |
||
684 | 'pretext' => $this->getPretext(), |
||
685 | 'color' => $this->getColor(), |
||
686 | 'footer' => $this->getFooter(), |
||
687 | 'footer_icon' => $this->getFooterIcon(), |
||
688 | 'ts' => $this->getTimestamp() ? $this->getTimestamp()->getTimestamp() : null, |
||
689 | 'mrkdwn_in' => $this->getMarkdownFields(), |
||
690 | 'image_url' => $this->getImageUrl(), |
||
691 | 'thumb_url' => $this->getThumbUrl(), |
||
692 | 'title' => $this->getTitle(), |
||
693 | 'title_link' => $this->getTitleLink(), |
||
694 | 'author_name' => $this->getAuthorName(), |
||
695 | 'author_link' => $this->getAuthorLink(), |
||
696 | 'author_icon' => $this->getAuthorIcon(), |
||
697 | ]; |
||
698 | |||
699 | $data['fields'] = $this->getFieldsAsArrays(); |
||
700 | $data['actions'] = $this->getActionsAsArrays(); |
||
701 | |||
702 | return $data; |
||
703 | } |
||
704 | |||
705 | /** |
||
706 | * Iterates over all fields in this attachment and returns |
||
707 | * them in their array form. |
||
708 | * |
||
709 | * @return array |
||
710 | */ |
||
711 | protected function getFieldsAsArrays() |
||
712 | { |
||
713 | $fields = []; |
||
714 | |||
715 | foreach ($this->getFields() as $field) { |
||
716 | $fields[] = $field->toArray(); |
||
717 | } |
||
718 | |||
719 | return $fields; |
||
720 | } |
||
721 | |||
722 | /** |
||
723 | * Iterates over all actions in this attachment and returns |
||
724 | * them in their array form. |
||
725 | * |
||
726 | * @return array |
||
727 | */ |
||
728 | protected function getActionsAsArrays() |
||
729 | { |
||
730 | $actions = []; |
||
731 | |||
732 | foreach ($this->getActions() as $action) { |
||
733 | $actions[] = $action->toArray(); |
||
734 | } |
||
735 | |||
736 | return $actions; |
||
737 | } |
||
738 | } |
||
739 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.