1 | <?php |
||
7 | class Client |
||
8 | { |
||
9 | /** |
||
10 | * The Slack incoming webhook endpoint. |
||
11 | * |
||
12 | * @var string |
||
13 | */ |
||
14 | protected $endpoint; |
||
15 | |||
16 | /** |
||
17 | * The default channel to send messages to. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $channel; |
||
22 | |||
23 | /** |
||
24 | * The default username to send messages as. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $username; |
||
29 | |||
30 | /** |
||
31 | * The default icon to send messages with. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $icon; |
||
36 | |||
37 | /** |
||
38 | * Whether to link names like @regan or leave |
||
39 | * them as plain text. |
||
40 | * |
||
41 | * @var bool |
||
42 | */ |
||
43 | protected $link_names = false; |
||
44 | |||
45 | /** |
||
46 | * Whether Slack should unfurl text-based URLs. |
||
47 | * |
||
48 | * @var bool |
||
49 | */ |
||
50 | protected $unfurl_links = false; |
||
51 | |||
52 | /** |
||
53 | * Whether Slack should unfurl media URLs. |
||
54 | * |
||
55 | * @var bool |
||
56 | */ |
||
57 | protected $unfurl_media = true; |
||
58 | |||
59 | /** |
||
60 | * Whether message text should be formatted with Slack's |
||
61 | * Markdown-like language. |
||
62 | * |
||
63 | * @var bool |
||
64 | */ |
||
65 | protected $allow_markdown = true; |
||
66 | |||
67 | /** |
||
68 | * The attachment fields which should be formatted with |
||
69 | * Slack's Markdown-like language. |
||
70 | * |
||
71 | * @var array |
||
72 | */ |
||
73 | protected $markdown_in_attachments = []; |
||
74 | |||
75 | /** |
||
76 | * The Guzzle HTTP client instance. |
||
77 | * |
||
78 | * @var \GuzzleHttp\Client |
||
79 | */ |
||
80 | protected $guzzle; |
||
81 | |||
82 | /** |
||
83 | * Instantiate a new Client. |
||
84 | * |
||
85 | * @param string $endpoint |
||
86 | * @param array $attributes |
||
87 | * @return void |
||
|
|||
88 | */ |
||
89 | public function __construct($endpoint, array $attributes = [], Guzzle $guzzle = null) |
||
127 | |||
128 | /** |
||
129 | * Pass any unhandled methods through to a new Message |
||
130 | * instance. |
||
131 | * |
||
132 | * @param string $name The name of the method |
||
133 | * @param array $arguments The method arguments |
||
134 | * @return \Maknz\Slack\Message |
||
135 | */ |
||
136 | public function __call($name, $arguments) |
||
144 | |||
145 | /** |
||
146 | * Get the Slack endpoint. |
||
147 | * |
||
148 | * @return string |
||
149 | */ |
||
150 | public function getEndpoint() |
||
154 | |||
155 | /** |
||
156 | * Set the Slack endpoint. |
||
157 | * |
||
158 | * @param string $endpoint |
||
159 | * @return void |
||
160 | */ |
||
161 | public function setEndpoint($endpoint) |
||
165 | |||
166 | /** |
||
167 | * Get the default channel messages will be created for. |
||
168 | * |
||
169 | * @return string |
||
170 | */ |
||
171 | public function getDefaultChannel() |
||
175 | |||
176 | /** |
||
177 | * Set the default channel messages will be created for. |
||
178 | * |
||
179 | * @param string $channel |
||
180 | * @return void |
||
181 | */ |
||
182 | public function setDefaultChannel($channel) |
||
186 | |||
187 | /** |
||
188 | * Get the default username messages will be created for. |
||
189 | * |
||
190 | * @return string |
||
191 | */ |
||
192 | public function getDefaultUsername() |
||
196 | |||
197 | /** |
||
198 | * Set the default username messages will be created for. |
||
199 | * |
||
200 | * @param string $username |
||
201 | * @return void |
||
202 | */ |
||
203 | public function setDefaultUsername($username) |
||
207 | |||
208 | /** |
||
209 | * Get the default icon messages will be created with. |
||
210 | * |
||
211 | * @return string |
||
212 | */ |
||
213 | public function getDefaultIcon() |
||
217 | |||
218 | /** |
||
219 | * Set the default icon messages will be created with. |
||
220 | * |
||
221 | * @param string $icon |
||
222 | * @return void |
||
223 | */ |
||
224 | public function setDefaultIcon($icon) |
||
228 | |||
229 | /** |
||
230 | * Get whether messages sent will have names (like @regan) |
||
231 | * will be converted into links. |
||
232 | * |
||
233 | * @return bool |
||
234 | */ |
||
235 | public function getLinkNames() |
||
239 | |||
240 | /** |
||
241 | * Set whether messages sent will have names (like @regan) |
||
242 | * will be converted into links. |
||
243 | * |
||
244 | * @param bool $value |
||
245 | * @return void |
||
246 | */ |
||
247 | public function setLinkNames($value) |
||
251 | |||
252 | /** |
||
253 | * Get whether text links should be unfurled. |
||
254 | * |
||
255 | * @return bool |
||
256 | */ |
||
257 | public function getUnfurlLinks() |
||
261 | |||
262 | /** |
||
263 | * Set whether text links should be unfurled. |
||
264 | * |
||
265 | * @param bool $value |
||
266 | * @return void |
||
267 | */ |
||
268 | public function setUnfurlLinks($value) |
||
272 | |||
273 | /** |
||
274 | * Get whether media links should be unfurled. |
||
275 | * |
||
276 | * @return bool |
||
277 | */ |
||
278 | public function getUnfurlMedia() |
||
282 | |||
283 | /** |
||
284 | * Set whether media links should be unfurled. |
||
285 | * |
||
286 | * @param bool $value |
||
287 | * @return void |
||
288 | */ |
||
289 | public function setUnfurlMedia($value) |
||
293 | |||
294 | /** |
||
295 | * Get whether message text should be formatted with |
||
296 | * Slack's Markdown-like language. |
||
297 | * |
||
298 | * @return bool |
||
299 | */ |
||
300 | public function getAllowMarkdown() |
||
304 | |||
305 | /** |
||
306 | * Set whether message text should be formatted with |
||
307 | * Slack's Markdown-like language. |
||
308 | * |
||
309 | * @param bool $value |
||
310 | * @return void |
||
311 | */ |
||
312 | public function setAllowMarkdown($value) |
||
316 | |||
317 | /** |
||
318 | * Get the attachment fields which should be formatted |
||
319 | * in Slack's Markdown-like language. |
||
320 | * |
||
321 | * @return array |
||
322 | */ |
||
323 | public function getMarkdownInAttachments() |
||
327 | |||
328 | /** |
||
329 | * Set the attachment fields which should be formatted |
||
330 | * in Slack's Markdown-like language. |
||
331 | * |
||
332 | * @param array $fields |
||
333 | * @return void |
||
334 | */ |
||
335 | public function setMarkdownInAttachments(array $fields) |
||
339 | |||
340 | /** |
||
341 | * Create a new message with defaults. |
||
342 | * |
||
343 | * @return \Maknz\Slack\Message |
||
344 | */ |
||
345 | public function createMessage() |
||
361 | |||
362 | /** |
||
363 | * Send a message. |
||
364 | * |
||
365 | * @param \Maknz\Slack\Message $message |
||
366 | * @return void |
||
367 | */ |
||
368 | public function sendMessage(Message $message) |
||
376 | |||
377 | /** |
||
378 | * Prepares the payload to be sent to the webhook. |
||
379 | * |
||
380 | * @param \Maknz\Slack\Message $message The message to send |
||
381 | * @return array |
||
382 | */ |
||
383 | public function preparePayload(Message $message) |
||
403 | |||
404 | /** |
||
405 | * Get the attachments in array form. |
||
406 | * |
||
407 | * @param \Maknz\Slack\Message $message |
||
408 | * @return array |
||
409 | */ |
||
410 | protected function getAttachmentsAsArrays(Message $message) |
||
420 | } |
||
421 |
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.