1 | <?php |
||
21 | class Target extends \yii\log\Target |
||
22 | { |
||
23 | /** |
||
24 | * @var Client|array|string Yii HTTP client configuration. |
||
25 | * This can be a component ID, a configuration array or a Client instance. |
||
26 | * @since 1.2 |
||
27 | */ |
||
28 | public $httpClient = [ |
||
29 | 'class' => 'yii\httpclient\Client', |
||
30 | ]; |
||
31 | |||
32 | /** |
||
33 | * @var string incoming webhook URL. |
||
34 | */ |
||
35 | public $webhookUrl; |
||
36 | |||
37 | /** |
||
38 | * @var string displayed username. |
||
39 | */ |
||
40 | public $username; |
||
41 | |||
42 | /** |
||
43 | * @var string icon URL. |
||
44 | */ |
||
45 | public $iconUrl; |
||
46 | |||
47 | /** |
||
48 | * @var string icon emoji. |
||
49 | */ |
||
50 | public $iconEmoji; |
||
51 | |||
52 | /** |
||
53 | * @var string channel or direct message name. |
||
54 | */ |
||
55 | public $channel; |
||
56 | |||
57 | /** |
||
58 | * @var string[] colors per a logger level. |
||
59 | */ |
||
60 | public $colors = [ |
||
61 | Logger::LEVEL_ERROR => 'danger', |
||
62 | Logger::LEVEL_WARNING => 'warning', |
||
63 | ]; |
||
64 | |||
65 | /** |
||
66 | * @inheritDoc |
||
67 | */ |
||
68 | public $exportInterval = 50; |
||
69 | |||
70 | /** |
||
71 | * @inheritDoc |
||
72 | */ |
||
73 | 5 | public function init() |
|
78 | |||
79 | /** |
||
80 | * @inheritDoc |
||
81 | * @throws \yii\base\InvalidValueException |
||
82 | */ |
||
83 | 2 | public function export() |
|
95 | |||
96 | /** |
||
97 | * Encodes special chars in a string as HTML entities. |
||
98 | * @param string $string |
||
99 | * @return string |
||
100 | * @since 1.3 |
||
101 | */ |
||
102 | 5 | protected function encode($string) |
|
106 | |||
107 | /** |
||
108 | * Returns a Slack API payload. |
||
109 | * @return array payload. |
||
110 | * @since 1.2 |
||
111 | */ |
||
112 | 3 | protected function getPayload() |
|
125 | |||
126 | /** |
||
127 | * Returns a properly formatted message attachment for Slack API. |
||
128 | * @param array $message raw message. |
||
129 | * @return array Slack message attachment. |
||
130 | */ |
||
131 | 4 | protected function formatMessageAttachment($message) |
|
164 | |||
165 | /** |
||
166 | * Inserts the new attachment field if the value is not empty. |
||
167 | * @param array $attachment |
||
168 | * @param string $title |
||
169 | * @param string|null $value |
||
170 | * @param bool $short |
||
171 | * @param bool $wrapAsCode |
||
172 | * @return $this |
||
173 | */ |
||
174 | 4 | private function insertField(array &$attachment, $title, $value, $short, $wrapAsCode = true) |
|
195 | |||
196 | /** |
||
197 | * Copies the value to the payload if the value is set. |
||
198 | * @param array $payload |
||
199 | * @param string $name |
||
200 | * @param string $value |
||
201 | * @return $this |
||
202 | */ |
||
203 | 3 | private function insertIntoPayload(array &$payload, $name, $value) |
|
210 | } |
||
211 |