Commit aab90c51 by Klimov Paul

'MessageInterface' updated to support 'method chain' call style.

parent ef6fea96
...@@ -45,6 +45,7 @@ class Message extends BaseMessage ...@@ -45,6 +45,7 @@ class Message extends BaseMessage
public function setCharset($charset) public function setCharset($charset)
{ {
$this->getSwiftMessage()->setCharset($charset); $this->getSwiftMessage()->setCharset($charset);
return $this;
} }
/** /**
...@@ -62,6 +63,7 @@ class Message extends BaseMessage ...@@ -62,6 +63,7 @@ class Message extends BaseMessage
{ {
$this->getSwiftMessage()->setFrom($from); $this->getSwiftMessage()->setFrom($from);
$this->getSwiftMessage()->setReplyTo($from); $this->getSwiftMessage()->setReplyTo($from);
return $this;
} }
/** /**
...@@ -78,6 +80,7 @@ class Message extends BaseMessage ...@@ -78,6 +80,7 @@ class Message extends BaseMessage
public function setTo($to) public function setTo($to)
{ {
$this->getSwiftMessage()->setTo($to); $this->getSwiftMessage()->setTo($to);
return $this;
} }
/** /**
...@@ -94,6 +97,7 @@ class Message extends BaseMessage ...@@ -94,6 +97,7 @@ class Message extends BaseMessage
public function setCc($cc) public function setCc($cc)
{ {
$this->getSwiftMessage()->setCc($cc); $this->getSwiftMessage()->setCc($cc);
return $this;
} }
/** /**
...@@ -110,6 +114,7 @@ class Message extends BaseMessage ...@@ -110,6 +114,7 @@ class Message extends BaseMessage
public function setBcc($bcc) public function setBcc($bcc)
{ {
$this->getSwiftMessage()->setBcc($bcc); $this->getSwiftMessage()->setBcc($bcc);
return $this;
} }
/** /**
...@@ -126,6 +131,7 @@ class Message extends BaseMessage ...@@ -126,6 +131,7 @@ class Message extends BaseMessage
public function setSubject($subject) public function setSubject($subject)
{ {
$this->getSwiftMessage()->setSubject($subject); $this->getSwiftMessage()->setSubject($subject);
return $this;
} }
/** /**
...@@ -142,6 +148,7 @@ class Message extends BaseMessage ...@@ -142,6 +148,7 @@ class Message extends BaseMessage
public function setText($text) public function setText($text)
{ {
$this->setBody($text, 'text/plain'); $this->setBody($text, 'text/plain');
return $this;
} }
/** /**
...@@ -150,6 +157,7 @@ class Message extends BaseMessage ...@@ -150,6 +157,7 @@ class Message extends BaseMessage
public function setHtml($html) public function setHtml($html)
{ {
$this->setBody($html, 'text/html'); $this->setBody($html, 'text/html');
return $this;
} }
/** /**
...@@ -209,6 +217,7 @@ class Message extends BaseMessage ...@@ -209,6 +217,7 @@ class Message extends BaseMessage
$attachment->setContentType($options['contentType']); $attachment->setContentType($options['contentType']);
} }
$this->getSwiftMessage()->attach($attachment); $this->getSwiftMessage()->attach($attachment);
return $this;
} }
/** /**
...@@ -224,6 +233,7 @@ class Message extends BaseMessage ...@@ -224,6 +233,7 @@ class Message extends BaseMessage
$attachment->setContentType($options['contentType']); $attachment->setContentType($options['contentType']);
} }
$this->getSwiftMessage()->attach($attachment); $this->getSwiftMessage()->attach($attachment);
return $this;
} }
/** /**
......
...@@ -10,6 +10,8 @@ namespace yii\mail; ...@@ -10,6 +10,8 @@ namespace yii\mail;
/** /**
* MailerInterface is an interface, which any mailer should apply. * MailerInterface is an interface, which any mailer should apply.
* *
* @see MessageInterface
*
* @author Paul Klimov <klimov.paul@gmail.com> * @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0 * @since 2.0
*/ */
......
...@@ -9,6 +9,19 @@ namespace yii\mail; ...@@ -9,6 +9,19 @@ namespace yii\mail;
/** /**
* MessageInterface is an interface, which email message should apply. * MessageInterface is an interface, which email message should apply.
* 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')
* ->renderText('text/view')
* ->renderHtml('html/view')
* ->send();
* ~~~
*
* @see MailerInterface
* *
* @author Paul Klimov <klimov.paul@gmail.com> * @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0 * @since 2.0
...@@ -18,6 +31,7 @@ interface MessageInterface ...@@ -18,6 +31,7 @@ interface MessageInterface
/** /**
* Set the character set of this message. * Set the character set of this message.
* @param string $charset character set name. * @param string $charset character set name.
* @return static self reference.
*/ */
public function setCharset($charset); public function setCharset($charset);
...@@ -27,6 +41,7 @@ interface MessageInterface ...@@ -27,6 +41,7 @@ interface MessageInterface
* You may pass an array of addresses if this message is from multiple people. * You may pass an array of addresses if this message is from multiple people.
* You may also specify sender name in addition to email address using format: * You may also specify sender name in addition to email address using format:
* [email => name]. * [email => name].
* @return static self reference.
*/ */
public function setFrom($from); public function setFrom($from);
...@@ -36,6 +51,7 @@ interface MessageInterface ...@@ -36,6 +51,7 @@ interface MessageInterface
* You may pass an array of addresses if multiple recipients should receive this message. * You may pass an array of addresses if multiple recipients should receive this message.
* You may also specify receiver name in addition to email address using format: * You may also specify receiver name in addition to email address using format:
* [email => name]. * [email => name].
* @return static self reference.
*/ */
public function setTo($to); public function setTo($to);
...@@ -45,6 +61,7 @@ interface MessageInterface ...@@ -45,6 +61,7 @@ interface MessageInterface
* You may pass an array of addresses if multiple recipients should receive this message. * You may pass an array of addresses if multiple recipients should receive this message.
* You may also specify receiver name in addition to email address using format: * You may also specify receiver name in addition to email address using format:
* [email => name]. * [email => name].
* @return static self reference.
*/ */
public function setCc($cc); public function setCc($cc);
...@@ -54,24 +71,28 @@ interface MessageInterface ...@@ -54,24 +71,28 @@ interface MessageInterface
* You may pass an array of addresses if multiple recipients should receive this message. * You may pass an array of addresses if multiple recipients should receive this message.
* You may also specify receiver name in addition to email address using format: * You may also specify receiver name in addition to email address using format:
* [email => name]. * [email => name].
* @return static self reference.
*/ */
public function setBcc($bcc); public function setBcc($bcc);
/** /**
* Sets message subject. * Sets message subject.
* @param string $subject message subject * @param string $subject message subject
* @return static self reference.
*/ */
public function setSubject($subject); public function setSubject($subject);
/** /**
* Sets message plain text content. * Sets message plain text content.
* @param string $text message plain text content. * @param string $text message plain text content.
* @return static self reference.
*/ */
public function setText($text); public function setText($text);
/** /**
* Sets message HTML content. * Sets message HTML content.
* @param string $html message HTML content. * @param string $html message HTML content.
* @return static self reference.
*/ */
public function setHtml($html); public function setHtml($html);
...@@ -81,6 +102,7 @@ interface MessageInterface ...@@ -81,6 +102,7 @@ interface MessageInterface
* @param array $options options for embed file. Valid options are: * @param array $options options for embed file. Valid options are:
* - fileName: name, which should be used to attach file. * - fileName: name, which should be used to attach file.
* - contentType: attached file MIME type. * - contentType: attached file MIME type.
* @return static self reference.
*/ */
public function attachContent($content, array $options = []); public function attachContent($content, array $options = []);
...@@ -90,6 +112,7 @@ interface MessageInterface ...@@ -90,6 +112,7 @@ interface MessageInterface
* @param array $options options for embed file. Valid options are: * @param array $options options for embed file. Valid options are:
* - fileName: name, which should be used to attach file. * - fileName: name, which should be used to attach file.
* - contentType: attached file MIME type. * - contentType: attached file MIME type.
* @return static self reference.
*/ */
public function attachFile($fileName, array $options = []); public function attachFile($fileName, array $options = []);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment