|
- <?php
-
-
- namespace yii\log;
-
- use Yii;
- use yii\base\InvalidConfigException;
- use yii\di\Instance;
- use yii\mail\MailerInterface;
-
-
- class EmailTarget extends Target
- {
-
-
- public $message = [];
-
-
- public $mailer = 'mailer';
-
-
-
-
- public function init()
- {
- parent::init();
- if (empty($this->message['to'])) {
- throw new InvalidConfigException('The "to" option must be set for EmailTarget::message.');
- }
- $this->mailer = Instance::ensure($this->mailer, 'yii\mail\MailerInterface');
- }
-
-
-
- public function export()
- {
-
-
- if (empty($this->message['subject'])) {
- $this->message['subject'] = 'Application Log';
- }
- $messages = array_map([$this, 'formatMessage'], $this->messages);
- $body = wordwrap(implode("\n", $messages), 70);
- $this->composeMessage($body)->send($this->mailer);
- }
-
-
-
- protected function composeMessage($body)
- {
- $message = $this->mailer->compose();
- Yii::configure($message, $this->message);
- $message->setTextBody($body);
-
- return $message;
- }
- }
|