1 | <?php |
||
8 | class Client |
||
9 | { |
||
10 | /** |
||
11 | * The Slack incoming webhook endpoint. |
||
12 | * |
||
13 | * @var string |
||
14 | */ |
||
15 | protected $endpoint; |
||
16 | |||
17 | /** |
||
18 | * The default channel to send messages to. |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $channel; |
||
23 | |||
24 | /** |
||
25 | * The default username to send messages as. |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $username; |
||
30 | |||
31 | /** |
||
32 | * The default icon to send messages with. |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $icon; |
||
37 | |||
38 | /** |
||
39 | * Whether to link names like @regan or leave |
||
40 | * them as plain text. |
||
41 | * |
||
42 | * @var bool |
||
43 | */ |
||
44 | protected $link_names = false; |
||
45 | |||
46 | /** |
||
47 | * Whether Slack should unfurl text-based URLs. |
||
48 | * |
||
49 | * @var bool |
||
50 | */ |
||
51 | protected $unfurl_links = false; |
||
52 | |||
53 | /** |
||
54 | * Whether Slack should unfurl media URLs. |
||
55 | * |
||
56 | * @var bool |
||
57 | */ |
||
58 | protected $unfurl_media = true; |
||
59 | |||
60 | /** |
||
61 | * Whether message text should be formatted with Slack's |
||
62 | * Markdown-like language. |
||
63 | * |
||
64 | * @var bool |
||
65 | */ |
||
66 | protected $allow_markdown = true; |
||
67 | |||
68 | /** |
||
69 | * The attachment fields which should be formatted with |
||
70 | * Slack's Markdown-like language. |
||
71 | * |
||
72 | * @var array |
||
73 | */ |
||
74 | protected $markdown_in_attachments = []; |
||
75 | |||
76 | /** |
||
77 | * The Guzzle HTTP client instance. |
||
78 | * |
||
79 | * @var \GuzzleHttp\Client |
||
80 | */ |
||
81 | protected $guzzle; |
||
82 | |||
83 | /** |
||
84 | * Instantiate a new Client. |
||
85 | * |
||
86 | * @param string $endpoint |
||
87 | * @param array $attributes |
||
88 | * @return void |
||
|
|||
89 | */ |
||
90 | public function __construct($endpoint, array $attributes = [], Guzzle $guzzle = null) |
||
128 | |||
129 | /** |
||
130 | * Pass any unhandled methods through to a new Message |
||
131 | * instance. |
||
132 | * |
||
133 | * @param string $name The name of the method |
||
134 | * @param array $arguments The method arguments |
||
135 | * @return \Maknz\Slack\Message |
||
136 | */ |
||
137 | public function __call($name, $arguments) |
||
141 | |||
142 | /** |
||
143 | * Get the Slack endpoint. |
||
144 | * |
||
145 | * @return string |
||
146 | */ |
||
147 | public function getEndpoint() |
||
151 | |||
152 | /** |
||
153 | * Set the Slack endpoint. |
||
154 | * |
||
155 | * @param string $endpoint |
||
156 | * @return void |
||
157 | */ |
||
158 | public function setEndpoint($endpoint) |
||
162 | |||
163 | /** |
||
164 | * Get the default channel messages will be created for. |
||
165 | * |
||
166 | * @return string |
||
167 | */ |
||
168 | public function getDefaultChannel() |
||
172 | |||
173 | /** |
||
174 | * Set the default channel messages will be created for. |
||
175 | * |
||
176 | * @param string $channel |
||
177 | * @return void |
||
178 | */ |
||
179 | public function setDefaultChannel($channel) |
||
183 | |||
184 | /** |
||
185 | * Get the default username messages will be created for. |
||
186 | * |
||
187 | * @return string |
||
188 | */ |
||
189 | public function getDefaultUsername() |
||
193 | |||
194 | /** |
||
195 | * Set the default username messages will be created for. |
||
196 | * |
||
197 | * @param string $username |
||
198 | * @return void |
||
199 | */ |
||
200 | public function setDefaultUsername($username) |
||
204 | |||
205 | /** |
||
206 | * Get the default icon messages will be created with. |
||
207 | * |
||
208 | * @return string |
||
209 | */ |
||
210 | public function getDefaultIcon() |
||
214 | |||
215 | /** |
||
216 | * Set the default icon messages will be created with. |
||
217 | * |
||
218 | * @param string $icon |
||
219 | * @return void |
||
220 | */ |
||
221 | public function setDefaultIcon($icon) |
||
225 | |||
226 | /** |
||
227 | * Get whether messages sent will have names (like @regan) |
||
228 | * will be converted into links. |
||
229 | * |
||
230 | * @return bool |
||
231 | */ |
||
232 | public function getLinkNames() |
||
236 | |||
237 | /** |
||
238 | * Set whether messages sent will have names (like @regan) |
||
239 | * will be converted into links. |
||
240 | * |
||
241 | * @param bool $value |
||
242 | * @return void |
||
243 | */ |
||
244 | public function setLinkNames($value) |
||
248 | |||
249 | /** |
||
250 | * Get whether text links should be unfurled. |
||
251 | * |
||
252 | * @return bool |
||
253 | */ |
||
254 | public function getUnfurlLinks() |
||
258 | |||
259 | /** |
||
260 | * Set whether text links should be unfurled. |
||
261 | * |
||
262 | * @param bool $value |
||
263 | * @return void |
||
264 | */ |
||
265 | public function setUnfurlLinks($value) |
||
269 | |||
270 | /** |
||
271 | * Get whether media links should be unfurled. |
||
272 | * |
||
273 | * @return bool |
||
274 | */ |
||
275 | public function getUnfurlMedia() |
||
279 | |||
280 | /** |
||
281 | * Set whether media links should be unfurled. |
||
282 | * |
||
283 | * @param bool $value |
||
284 | * @return void |
||
285 | */ |
||
286 | public function setUnfurlMedia($value) |
||
290 | |||
291 | /** |
||
292 | * Get whether message text should be formatted with |
||
293 | * Slack's Markdown-like language. |
||
294 | * |
||
295 | * @return bool |
||
296 | */ |
||
297 | public function getAllowMarkdown() |
||
301 | |||
302 | /** |
||
303 | * Set whether message text should be formatted with |
||
304 | * Slack's Markdown-like language. |
||
305 | * |
||
306 | * @param bool $value |
||
307 | * @return void |
||
308 | */ |
||
309 | public function setAllowMarkdown($value) |
||
313 | |||
314 | /** |
||
315 | * Get the attachment fields which should be formatted |
||
316 | * in Slack's Markdown-like language. |
||
317 | * |
||
318 | * @return array |
||
319 | */ |
||
320 | public function getMarkdownInAttachments() |
||
324 | |||
325 | /** |
||
326 | * Set the attachment fields which should be formatted |
||
327 | * in Slack's Markdown-like language. |
||
328 | * |
||
329 | * @param array $fields |
||
330 | * @return void |
||
331 | */ |
||
332 | public function setMarkdownInAttachments(array $fields) |
||
336 | |||
337 | /** |
||
338 | * Create a new message with defaults. |
||
339 | * |
||
340 | * @return \Maknz\Slack\Message |
||
341 | */ |
||
342 | public function createMessage() |
||
358 | |||
359 | /** |
||
360 | * Send a message. |
||
361 | * |
||
362 | * @param \Maknz\Slack\Message $message |
||
363 | * @return void |
||
364 | */ |
||
365 | public function sendMessage(Message $message) |
||
377 | |||
378 | /** |
||
379 | * Prepares the payload to be sent to the webhook. |
||
380 | * |
||
381 | * @param \Maknz\Slack\Message $message The message to send |
||
382 | * @return array |
||
383 | */ |
||
384 | public function preparePayload(Message $message) |
||
404 | |||
405 | /** |
||
406 | * Get the attachments in array form. |
||
407 | * |
||
408 | * @param \Maknz\Slack\Message $message |
||
409 | * @return array |
||
410 | */ |
||
411 | protected function getAttachmentsAsArrays(Message $message) |
||
421 | } |
||
422 |
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.