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 | 5 | public function __construct($config = []) |
|
73 | |||
74 | /** |
||
75 | * @inheritDoc |
||
76 | * @throws \yii\base\InvalidConfigException |
||
77 | */ |
||
78 | 5 | public function init() |
|
83 | |||
84 | /** |
||
85 | * @inheritDoc |
||
86 | * @throws \yii\base\InvalidValueException |
||
87 | */ |
||
88 | 2 | public function export() |
|
100 | |||
101 | /** |
||
102 | * Encodes special chars in a string as HTML entities. |
||
103 | * @param string $string |
||
104 | * @return string |
||
105 | * @since 1.3 |
||
106 | */ |
||
107 | 1 | protected function encode($string) |
|
111 | |||
112 | /** |
||
113 | * Returns a Slack API payload. |
||
114 | * @return array payload. |
||
115 | * @since 1.2 |
||
116 | */ |
||
117 | 1 | protected function getPayload() |
|
130 | |||
131 | /** |
||
132 | * Returns a properly formatted message attachment for Slack API. |
||
133 | * @param array $message raw message. |
||
134 | * @return array Slack message attachment. |
||
135 | */ |
||
136 | 2 | protected function formatMessageAttachment($message) |
|
169 | |||
170 | /** |
||
171 | * Inserts the new attachment field if the value is not empty. |
||
172 | * @param array $attachment |
||
173 | * @param string $title |
||
174 | * @param string|null $value |
||
175 | * @param bool $short |
||
176 | * @param bool $wrapAsCode |
||
177 | * @return $this |
||
178 | */ |
||
179 | 4 | private function insertField(array &$attachment, $title, $value, $short, $wrapAsCode = true) |
|
200 | |||
201 | /** |
||
202 | * Copies the value to the payload if the value is set. |
||
203 | * @param array $payload |
||
204 | * @param string $name |
||
205 | * @param string $value |
||
206 | * @return $this |
||
207 | */ |
||
208 | 3 | private function insertIntoPayload(array &$payload, $name, $value) |
|
215 | } |
||
216 |