mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-10 02:13:17 +08:00
'yii\mail\MessageInterface' updated:
- setter methods renamed to have pure name - method 'createMessage' renamed to 'compose'
This commit is contained in:
@ -45,10 +45,18 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
|
||||
/**
|
||||
* @var array configuration, which should be applied by default to any new created
|
||||
* email message instance.
|
||||
* In addition to normal [[Yii::createObject()]] behavior extra config keys are available:
|
||||
* - 'from' invokes [[MessageInterface::from()]]
|
||||
* - 'to' invokes [[MessageInterface::to()]]
|
||||
* - 'cc' invokes [[MessageInterface::cc()]]
|
||||
* - 'bcc' invokes [[MessageInterface::bcc()]]
|
||||
* - 'subject' invokes [[MessageInterface::subject()]]
|
||||
* - 'text' invokes [[MessageInterface::text()]]
|
||||
* - 'html' invokes [[MessageInterface::html()]]
|
||||
* For example:
|
||||
* ~~~
|
||||
* array(
|
||||
* 'encoding' => 'UTF-8',
|
||||
* 'charset' => 'UTF-8',
|
||||
* 'from' => 'noreply@mydomain.com',
|
||||
* 'bcc' => 'email.test@mydomain.com',
|
||||
* )
|
||||
@ -100,16 +108,37 @@ abstract class BaseMailer extends Component implements MailerInterface, ViewCont
|
||||
* Creates new message instance from given configuration.
|
||||
* Message configuration will be merged with [[messageConfig]].
|
||||
* If 'class' parameter is omitted [[messageClass]], will be used.
|
||||
* @param array $config message configuration.
|
||||
* @param array $config message configuration. See [[messageConfig]]
|
||||
* for the configuration format details.
|
||||
* @return MessageInterface message instance.
|
||||
*/
|
||||
public function createMessage(array $config = [])
|
||||
public function compose(array $config = [])
|
||||
{
|
||||
$config = array_merge($this->messageConfig, $config);
|
||||
if (!array_key_exists('class', $config)) {
|
||||
$config['class'] = $this->messageClass;
|
||||
}
|
||||
return Yii::createObject($config);
|
||||
$configMethodNames = [
|
||||
'from',
|
||||
'to',
|
||||
'cc',
|
||||
'bcc',
|
||||
'subject',
|
||||
'text',
|
||||
'html',
|
||||
];
|
||||
$methodBasedConfig = [];
|
||||
foreach ($config as $name => $value) {
|
||||
if (in_array($name, $configMethodNames, true)) {
|
||||
$methodBasedConfig[$name] = $value;
|
||||
unset($config[$name]);
|
||||
}
|
||||
}
|
||||
$message = Yii::createObject($config);
|
||||
foreach ($methodBasedConfig as $name => $value) {
|
||||
$message->$name($value);
|
||||
}
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -22,13 +22,6 @@ use Yii;
|
||||
*
|
||||
* @property \yii\mail\BaseMailer $mailer mailer component instance. This property is read-only.
|
||||
* @property string $charset the character set of this message.
|
||||
* @property string|array $from sender email address.
|
||||
* @property string|array $to receiver email address.
|
||||
* @property string|array $cc copy receiver email address.
|
||||
* @property string|array $bcc hidden copy receiver email address.
|
||||
* @property string $subject message subject.
|
||||
* @property string $text message plain text content.
|
||||
* @property string $html message HTML content.
|
||||
*
|
||||
* @author Paul Klimov <klimov.paul@gmail.com>
|
||||
* @since 2.0
|
||||
@ -56,7 +49,7 @@ abstract class BaseMessage extends Object implements MessageInterface
|
||||
*/
|
||||
public function renderHtml($view, $params = [])
|
||||
{
|
||||
$this->setHtml($this->getMailer()->render($view, $params, $this->getMailer()->htmlLayout));
|
||||
$this->html($this->getMailer()->render($view, $params, $this->getMailer()->htmlLayout));
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -65,7 +58,7 @@ abstract class BaseMessage extends Object implements MessageInterface
|
||||
*/
|
||||
public function renderText($view, $params = [])
|
||||
{
|
||||
$this->setText($this->getMailer()->render($view, $params, $this->getMailer()->textLayout));
|
||||
$this->text($this->getMailer()->render($view, $params, $this->getMailer()->textLayout));
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@ -22,7 +22,7 @@ interface MailerInterface
|
||||
* @param array $config message configuration.
|
||||
* @return MessageInterface message instance.
|
||||
*/
|
||||
public function createMessage(array $config = []);
|
||||
public function compose(array $config = []);
|
||||
|
||||
/**
|
||||
* Sends the given email message.
|
||||
|
||||
@ -12,10 +12,10 @@ namespace yii\mail;
|
||||
* Together with application component, which matches the [[MailerInterface]],
|
||||
* it introduces following mail sending syntax:
|
||||
* ~~~php
|
||||
* Yii::$app->mail->createMessage()
|
||||
* ->setFrom('from@domain.com')
|
||||
* ->setTo('to@domain.com')
|
||||
* ->setSubject('Message Subject')
|
||||
* Yii::$app->mail->compose()
|
||||
* ->from('from@domain.com')
|
||||
* ->to('to@domain.com')
|
||||
* ->subject('Message Subject')
|
||||
* ->renderText('text/view')
|
||||
* ->renderHtml('html/view')
|
||||
* ->send();
|
||||
@ -43,7 +43,7 @@ interface MessageInterface
|
||||
* [email => name].
|
||||
* @return static self reference.
|
||||
*/
|
||||
public function setFrom($from);
|
||||
public function from($from);
|
||||
|
||||
/**
|
||||
* Sets message receiver.
|
||||
@ -53,7 +53,7 @@ interface MessageInterface
|
||||
* [email => name].
|
||||
* @return static self reference.
|
||||
*/
|
||||
public function setTo($to);
|
||||
public function to($to);
|
||||
|
||||
/**
|
||||
* Set the Cc (additional copy receiver) addresses of this message.
|
||||
@ -63,7 +63,7 @@ interface MessageInterface
|
||||
* [email => name].
|
||||
* @return static self reference.
|
||||
*/
|
||||
public function setCc($cc);
|
||||
public function cc($cc);
|
||||
|
||||
/**
|
||||
* Set the Bcc (hidden copy receiver) addresses of this message.
|
||||
@ -73,28 +73,28 @@ interface MessageInterface
|
||||
* [email => name].
|
||||
* @return static self reference.
|
||||
*/
|
||||
public function setBcc($bcc);
|
||||
public function bcc($bcc);
|
||||
|
||||
/**
|
||||
* Sets message subject.
|
||||
* @param string $subject message subject
|
||||
* @return static self reference.
|
||||
*/
|
||||
public function setSubject($subject);
|
||||
public function subject($subject);
|
||||
|
||||
/**
|
||||
* Sets message plain text content.
|
||||
* @param string $text message plain text content.
|
||||
* @return static self reference.
|
||||
*/
|
||||
public function setText($text);
|
||||
public function text($text);
|
||||
|
||||
/**
|
||||
* Sets message HTML content.
|
||||
* @param string $html message HTML content.
|
||||
* @return static self reference.
|
||||
*/
|
||||
public function setHtml($html);
|
||||
public function html($html);
|
||||
|
||||
/**
|
||||
* Attach specified content as file for the email message.
|
||||
|
||||
Reference in New Issue
Block a user