1 | <?php |
||
11 | class RocketChatAttachment |
||
12 | { |
||
13 | /** @var string|null The color you want the order on the left side to be, any value background-css supports. */ |
||
14 | protected $color; |
||
15 | |||
16 | /** @var string|null The text to display for this attachment, it is different than the message’s text. */ |
||
17 | protected $text; |
||
18 | |||
19 | /** @var string|null Displays the time next to the text portion. */ |
||
20 | protected $timestamp; |
||
21 | |||
22 | /** @var string|null An image that displays to the left of the text, looks better when this is relatively small. */ |
||
23 | protected $thumbnailUrl; |
||
24 | |||
25 | /** @var string|null Only applicable if the ts is provided, as it makes the time clickable to this link. */ |
||
26 | protected $messageLink; |
||
27 | |||
28 | /** @var bool Causes the image, audio, and video sections to be hiding when collapsed is true. */ |
||
29 | protected $collapsed = false; |
||
30 | |||
31 | /** @var string|null Name of the author. */ |
||
32 | protected $authorName; |
||
33 | |||
34 | /** @var string|null Providing this makes the author name clickable and points to this link. */ |
||
35 | protected $authorLink; |
||
36 | |||
37 | /** @var string|null Displays a tiny icon to the left of the Author’s name. */ |
||
38 | protected $authorIcon; |
||
39 | |||
40 | /** @var string|null Title to display for this attachment, displays under the author. */ |
||
41 | protected $title; |
||
42 | |||
43 | /** @var string|null Providing this makes the title clickable, pointing to this link. */ |
||
44 | protected $titleLink; |
||
45 | |||
46 | /** @var bool When this is true, a download icon appears and clicking this saves the link to file. */ |
||
47 | protected $titleLinkDownload = false; |
||
48 | |||
49 | /** @var string|null The image to display, will be “big” and easy to see. */ |
||
50 | protected $imageUrl; |
||
51 | |||
52 | /** @var string|null Audio file to play, only supports what html audio does. */ |
||
53 | protected $audioUrl; |
||
54 | |||
55 | /** @var string|null Video file to play, only supports what html video does. */ |
||
56 | protected $videoUrl; |
||
57 | |||
58 | /** @var array An array of Attachment Field Objects. */ |
||
59 | protected $fields = []; |
||
60 | |||
61 | /** |
||
62 | * RocketChatAttachment constructor. |
||
63 | * |
||
64 | * @param array $data |
||
65 | */ |
||
66 | 27 | public function __construct(array $data = []) |
|
67 | { |
||
68 | 27 | $this->setPropertiesFromArray($data); |
|
69 | 27 | } |
|
70 | |||
71 | /** |
||
72 | * Create a new instance of RocketChatAttachment. |
||
73 | * |
||
74 | * @param array $data |
||
75 | * @return \NotificationChannels\RocketChat\RocketChatAttachment |
||
76 | */ |
||
77 | 3 | public static function create(array $data = []) |
|
81 | |||
82 | /** |
||
83 | * @param string $color |
||
84 | * @return \NotificationChannels\RocketChat\RocketChatAttachment |
||
85 | */ |
||
86 | 1 | public function color(string $color): self |
|
92 | |||
93 | /** |
||
94 | * @param string $text |
||
95 | * @return \NotificationChannels\RocketChat\RocketChatAttachment |
||
96 | */ |
||
97 | 1 | public function text(string $text): self |
|
103 | |||
104 | /** |
||
105 | * @param string|\DateTimeInterface $timestamp |
||
106 | * @return \NotificationChannels\RocketChat\RocketChatAttachment |
||
107 | */ |
||
108 | 4 | public function timestamp($timestamp): self |
|
129 | |||
130 | /** |
||
131 | * @param string $thumbnailUrl |
||
132 | * @return \NotificationChannels\RocketChat\RocketChatAttachment |
||
133 | */ |
||
134 | 1 | public function thumbnailUrl(string $thumbnailUrl): self |
|
140 | |||
141 | /** |
||
142 | * @param string $messageLink |
||
143 | * @return \NotificationChannels\RocketChat\RocketChatAttachment |
||
144 | */ |
||
145 | 1 | public function messageLink(string $messageLink): self |
|
151 | |||
152 | /** |
||
153 | * @param bool $collapsed |
||
154 | * @return \NotificationChannels\RocketChat\RocketChatAttachment |
||
155 | */ |
||
156 | 1 | public function collapsed(bool $collapsed): self |
|
162 | |||
163 | /** |
||
164 | * @param string $name |
||
165 | * @param string $link |
||
166 | * @param string $icon |
||
167 | * @return \NotificationChannels\RocketChat\RocketChatAttachment |
||
168 | */ |
||
169 | 1 | public function author(string $name, string $link = '', string $icon = ''): self |
|
177 | |||
178 | /** |
||
179 | * @param string $authorName |
||
180 | * @return \NotificationChannels\RocketChat\RocketChatAttachment |
||
181 | */ |
||
182 | 2 | public function authorName(string $authorName): self |
|
188 | |||
189 | /** |
||
190 | * @param string $authorLink |
||
191 | * @return \NotificationChannels\RocketChat\RocketChatAttachment |
||
192 | */ |
||
193 | 2 | public function authorLink(string $authorLink): self |
|
199 | |||
200 | /** |
||
201 | * @param string $authorIcon |
||
202 | * @return \NotificationChannels\RocketChat\RocketChatAttachment |
||
203 | */ |
||
204 | 2 | public function authorIcon(string $authorIcon): self |
|
210 | |||
211 | /** |
||
212 | * @param string $title |
||
213 | * @return \NotificationChannels\RocketChat\RocketChatAttachment |
||
214 | */ |
||
215 | 5 | public function title(string $title): self |
|
221 | |||
222 | /** |
||
223 | * @param string $titleLink |
||
224 | * @return \NotificationChannels\RocketChat\RocketChatAttachment |
||
225 | */ |
||
226 | 1 | public function titleLink(string $titleLink): self |
|
232 | |||
233 | /** |
||
234 | * @param bool $titleLinkDownload |
||
235 | * @return \NotificationChannels\RocketChat\RocketChatAttachment |
||
236 | */ |
||
237 | 1 | public function titleLinkDownload(bool $titleLinkDownload): self |
|
243 | |||
244 | /** |
||
245 | * @param string $imageUrl |
||
246 | * @return \NotificationChannels\RocketChat\RocketChatAttachment |
||
247 | */ |
||
248 | 1 | public function imageUrl(string $imageUrl): self |
|
254 | |||
255 | /** |
||
256 | * @param string $audioUrl |
||
257 | * @return \NotificationChannels\RocketChat\RocketChatAttachment |
||
258 | */ |
||
259 | 1 | public function audioUrl(string $audioUrl): self |
|
265 | |||
266 | /** |
||
267 | * @param string $videoUrl |
||
268 | * @return \NotificationChannels\RocketChat\RocketChatAttachment |
||
269 | */ |
||
270 | 1 | public function videoUrl(string $videoUrl): self |
|
276 | |||
277 | /** |
||
278 | * @param array $fields |
||
279 | * @return \NotificationChannels\RocketChat\RocketChatAttachment |
||
280 | */ |
||
281 | 1 | public function fields(array $fields): self |
|
287 | |||
288 | /** |
||
289 | * Get an array representation of the RocketChatAttachment. |
||
290 | * |
||
291 | * @return array |
||
292 | */ |
||
293 | 26 | public function toArray(): array |
|
314 | |||
315 | /** |
||
316 | * Set attachment data from array. |
||
317 | * |
||
318 | * @param array $data |
||
319 | * @return void |
||
320 | */ |
||
321 | 27 | private function setPropertiesFromArray(array $data): void |
|
333 | } |
||
334 |