1 | <?php |
||
18 | class Target extends \yii\log\Target |
||
19 | { |
||
20 | /** |
||
21 | * @var Client|array|string Yii HTTP client configuration. |
||
22 | * This can be a component ID, a configuration array or a Client instance. |
||
23 | */ |
||
24 | public $httpClient = [ |
||
25 | 'class' => 'yii\httpclient\Client', |
||
26 | ]; |
||
27 | |||
28 | /** |
||
29 | * @var string bot token. |
||
30 | * @see https://core.telegram.org/bots/api#authorizing-your-bot |
||
31 | */ |
||
32 | public $token; |
||
33 | |||
34 | /** |
||
35 | * @var int|string unique identifier for the target chat or username of the target channel |
||
36 | * (in the format `{@}channelusername`). |
||
37 | */ |
||
38 | public $chatId; |
||
39 | |||
40 | /** |
||
41 | * @var string log message template. |
||
42 | */ |
||
43 | public $template = '{levelAndRequest} |
||
44 | |||
45 | {text} |
||
46 | |||
47 | {category} |
||
48 | {user} |
||
49 | {stackTrace}'; |
||
50 | |||
51 | /** |
||
52 | * @var array log message template substitutions. |
||
53 | * [[defaultSubstitutions()]] will be used by default. |
||
54 | */ |
||
55 | public $substitutions; |
||
56 | |||
57 | /** |
||
58 | * @var bool|bool[] whether to send the message silently (`bool` or an array of `bool` per a logger level). |
||
59 | * iOS users will not receive a notification, Android users will receive a notification with no sound. |
||
60 | */ |
||
61 | public $enableNotification = true; |
||
62 | |||
63 | /** |
||
64 | * @var string[] level emoji per a logger level. |
||
65 | * @since 2.0 |
||
66 | */ |
||
67 | public $levelEmojis = [ |
||
68 | Logger::LEVEL_ERROR => '☠️', |
||
69 | Logger::LEVEL_WARNING => '⚠️', |
||
70 | Logger::LEVEL_INFO => 'ℹ️', |
||
71 | Logger::LEVEL_TRACE => '📝', |
||
72 | ]; |
||
73 | |||
74 | /** |
||
75 | * @inheritDoc |
||
76 | */ |
||
77 | public function __construct($config = []) |
||
82 | |||
83 | /** |
||
84 | * @inheritDoc |
||
85 | */ |
||
86 | public function init() |
||
94 | |||
95 | /** |
||
96 | * @inheritDoc |
||
97 | * @throws \yii\base\InvalidValueException |
||
98 | */ |
||
99 | public function export() |
||
118 | |||
119 | /** |
||
120 | * Returns a `sendMessage` request for Telegram. |
||
121 | * @param array $message raw message. |
||
122 | * @return array request as an array. |
||
123 | */ |
||
124 | protected function formatMessageRequest($message) |
||
149 | |||
150 | /** |
||
151 | * Returns an array with the default substitutions. |
||
152 | * @return array default substitutions. |
||
153 | */ |
||
154 | protected function defaultSubstitutions() |
||
218 | |||
219 | /** |
||
220 | * Returns a substituted value. |
||
221 | * @param string $name |
||
222 | * @param Message $message |
||
223 | * @return string |
||
224 | */ |
||
225 | private function substitute($name, Message $message) |
||
248 | } |
||
249 |