Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

67 rindas
2.0KB

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