1 | <?php |
||
19 | class SlackTarget extends Target |
||
20 | { |
||
21 | /** |
||
22 | * @var Client|array|string Yii HTTP client configuration. |
||
23 | * This can be a component ID, a configuration array or a Client instance. |
||
24 | * @since 1.2 |
||
25 | */ |
||
26 | public $httpClient = [ |
||
27 | 'class' => 'yii\httpclient\Client', |
||
28 | ]; |
||
29 | |||
30 | /** |
||
31 | * @var string incoming webhook URL. |
||
32 | */ |
||
33 | public $webhookUrl; |
||
34 | |||
35 | /** |
||
36 | * @var string displayed username. |
||
37 | */ |
||
38 | public $username; |
||
39 | |||
40 | /** |
||
41 | * @var string icon URL. |
||
42 | */ |
||
43 | public $iconUrl; |
||
44 | |||
45 | /** |
||
46 | * @var string icon emoji. |
||
47 | */ |
||
48 | public $iconEmoji; |
||
49 | |||
50 | /** |
||
51 | * @var string channel or direct message name. |
||
52 | */ |
||
53 | public $channel; |
||
54 | |||
55 | /** |
||
56 | * @var string[] colors per a logger level. |
||
57 | */ |
||
58 | public $colors = [ |
||
59 | Logger::LEVEL_ERROR => 'danger', |
||
60 | Logger::LEVEL_WARNING => 'warning', |
||
61 | ]; |
||
62 | |||
63 | /** |
||
64 | * @inheritDoc |
||
65 | */ |
||
66 | public $exportInterval = 50; |
||
67 | |||
68 | /** |
||
69 | * @inheritDoc |
||
70 | */ |
||
71 | 5 | public function init() |
|
76 | |||
77 | /** |
||
78 | * @inheritDoc |
||
79 | */ |
||
80 | 2 | public function export() |
|
93 | |||
94 | /** |
||
95 | * Encodes special chars in a message as HTML entities. |
||
96 | * @param string $message |
||
97 | * @return string |
||
98 | * @deprecated 1.3 |
||
99 | * @see encode() |
||
100 | */ |
||
101 | 1 | protected function encodeMessage($message) |
|
105 | |||
106 | /** |
||
107 | * Encodes special chars in a string as HTML entities. |
||
108 | * @param string $string |
||
109 | * @return string |
||
110 | * @since 1.3 |
||
111 | */ |
||
112 | 5 | protected function encode($string) |
|
116 | |||
117 | /** |
||
118 | * Returns a Slack API payload. |
||
119 | * @return array |
||
120 | * @since 1.2 |
||
121 | */ |
||
122 | 3 | protected function getPayload() |
|
135 | |||
136 | /** |
||
137 | * Returns a properly formatted message attachment for Slack API. |
||
138 | * @param array $message |
||
139 | * @return array |
||
140 | */ |
||
141 | 4 | protected function formatMessageAttachment($message) |
|
174 | |||
175 | /** |
||
176 | * Inserts the new attachment field if the value is not empty. |
||
177 | * @param array $attachment |
||
178 | * @param string $title |
||
179 | * @param string|null $value |
||
180 | * @param bool $short |
||
181 | * @param bool $encodeValue |
||
182 | * @return $this |
||
183 | */ |
||
184 | 4 | private function insertField(array &$attachment, $title, $value, $short, $encodeValue = true) |
|
205 | |||
206 | /** |
||
207 | * Copies the value to the payload if the value is set. |
||
208 | * @param array $payload |
||
209 | * @param string $name |
||
210 | * @param string $value |
||
211 | * @return $this |
||
212 | */ |
||
213 | 3 | private function insertIntoPayload(array &$payload, $name, $value) |
|
220 | } |
||
221 |