-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBaseMessage.php
52 lines (46 loc) · 1.56 KB
/
BaseMessage.php
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
<?php
namespace bashkarev\swiftmailer;
use Yii;
/**
* BaseMessage serves as a base class that implements the [[send()]] method required by [[MessageInterface]].
* @author Dmitriy Bashkarev <[email protected]>
* @author Paul Klimov <[email protected]>
*/
abstract class BaseMessage extends \CComponent 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()->getComponent('mailer');
} 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) {
return '';
}
}
}