1 | <?php |
||
15 | final class Attachment implements JsonSerializable |
||
16 | { |
||
17 | /** |
||
18 | * The attachment itself. |
||
19 | * We enable markdown in everything, why wouldn't we? |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | private $attachment = ['mrkdwn_in' => ["pretext", "text", "fields"]]; |
||
24 | |||
25 | /** |
||
26 | * Attachment constructor. |
||
27 | * I opted for setters since there are so many optional parameters. |
||
28 | * A new instance would look be messy if you only needed the last optional parameter. |
||
29 | * |
||
30 | * @param string $fallback A plain-text summary of the attachment. |
||
31 | */ |
||
32 | 9 | public function __construct($fallback) |
|
40 | |||
41 | /** |
||
42 | * This is the main text in a message attachment. |
||
43 | * |
||
44 | * @param string $text |
||
45 | * |
||
46 | * @return self |
||
47 | */ |
||
48 | 1 | public function setText($text) |
|
54 | |||
55 | /** |
||
56 | * This value is used to color the border along the left side of the message attachment. |
||
57 | * |
||
58 | * @param Colour $colour |
||
59 | * |
||
60 | * @return self |
||
61 | */ |
||
62 | 1 | public function setColour(Colour $colour) |
|
68 | |||
69 | /** |
||
70 | * This is optional text that appears above the message attachment block. |
||
71 | * |
||
72 | * @param string $pretext |
||
73 | * |
||
74 | * @return self |
||
75 | */ |
||
76 | 1 | public function setPretext($pretext) |
|
82 | |||
83 | /** |
||
84 | * The author parameters will display a small section at the top of a message attachment. |
||
85 | * |
||
86 | * @param Author $author |
||
87 | * |
||
88 | * @return self |
||
89 | */ |
||
90 | 1 | public function setAuthor(Author $author) |
|
104 | |||
105 | /** |
||
106 | * The title is displayed as larger, bold text near the top of a message attachment. |
||
107 | * |
||
108 | * @param Title $title |
||
109 | * |
||
110 | * @return self |
||
111 | */ |
||
112 | 1 | public function setTitle(Title $title) |
|
122 | |||
123 | /** |
||
124 | * Will be displayed in a table inside the message attachment. |
||
125 | * |
||
126 | * @param Field $field |
||
127 | * |
||
128 | * @return self |
||
129 | */ |
||
130 | 1 | public function addField(Field $field) |
|
140 | |||
141 | /** |
||
142 | * Add multiple fields in 1 call. |
||
143 | * |
||
144 | * @param Field[] $fields |
||
145 | * |
||
146 | * @return self |
||
147 | */ |
||
148 | public function addFields(array $fields) |
||
156 | |||
157 | /** |
||
158 | * A valid URL to an image file that will be displayed inside a message attachment. |
||
159 | * |
||
160 | * @param Url $image |
||
161 | * |
||
162 | * @return self |
||
163 | */ |
||
164 | 1 | public function setImage(Url $image) |
|
170 | |||
171 | /** |
||
172 | * A valid URL to an image file that will be displayed as a thumbnail on the right side of a message attachment. |
||
173 | * |
||
174 | * @param Url $thumbnail |
||
175 | * |
||
176 | * @return self |
||
177 | */ |
||
178 | 1 | public function setThumbnail(Url $thumbnail) |
|
184 | |||
185 | /** |
||
186 | * @inheritDoc |
||
187 | */ |
||
188 | 9 | public function jsonSerialize() |
|
192 | |||
193 | /** |
||
194 | * Get the attachment in the format that slack requires. |
||
195 | * |
||
196 | * @return array |
||
197 | */ |
||
198 | 9 | public function get() |
|
202 | } |
||
203 |