Blame view

vendor/yiisoft/yii2/mail/BaseMessage.php 1.96 KB
abf1649b   andryeyev   Чистая установка ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  <?php
  /**
   * @link http://www.yiiframework.com/
   * @copyright Copyright (c) 2008 Yii Software LLC
   * @license http://www.yiiframework.com/license/
   */
  
  namespace yii\mail;
  
  use yii\base\ErrorHandler;
  use yii\base\Object;
  use Yii;
  
  /**
   * BaseMessage serves as a base class that implements the [[send()]] method required by [[MessageInterface]].
   *
   * By default, [[send()]] will use the "mail" application component to send the current message.
   * The "mail" application component should be a mailer instance implementing [[MailerInterface]].
   *
   * @see BaseMailer
   *
   * @author Paul Klimov <klimov.paul@gmail.com>
   * @since 2.0
   */
  abstract class BaseMessage extends Object implements MessageInterface
  {
      /**
       * @var MailerInterface the mailer instance that created this message.
       * For independently created messages this is `null`.
       */
      public $mailer;
  
  
      /**
       * Sends this email message.
       * @param MailerInterface $mailer the mailer that should be used to send this message.
       * If no mailer is given it will first check if [[mailer]] is set and if not,
       * the "mail" application component will be used instead.
       * @return boolean whether this message is sent successfully.
       */
      public function send(MailerInterface $mailer = null)
      {
          if ($mailer === null && $this->mailer === null) {
              $mailer = Yii::$app->getMailer();
          } elseif ($mailer === null) {
              $mailer = $this->mailer;
          }
          return $mailer->send($this);
      }
  
      /**
       * PHP magic method that returns the string representation of this object.
       * @return string the string representation of this object.
       */
      public function __toString()
      {
          // __toString cannot throw exception
          // use trigger_error to bypass this limitation
          try {
              return $this->toString();
          } catch (\Exception $e) {
              ErrorHandler::convertExceptionToError($e);
              return '';
          }
      }
  }