From d33519e3e5afffddeed7dc5e6cbd359b7ad27fd4 Mon Sep 17 00:00:00 2001 From: Paul Klimov Date: Fri, 25 Oct 2013 16:58:30 +0300 Subject: [PATCH] Method 'MessageInterface::__toString()' added --- .../swiftmailer/yii/swiftmailer/Message.php | 48 +++++++++++++++++++ framework/yii/mail/MessageInterface.php | 7 +++ tests/unit/framework/mail/BaseMailerTest.php | 5 ++ 3 files changed, 60 insertions(+) diff --git a/extensions/swiftmailer/yii/swiftmailer/Message.php b/extensions/swiftmailer/yii/swiftmailer/Message.php index 8ae3ee41d3..bfefcde39b 100644 --- a/extensions/swiftmailer/yii/swiftmailer/Message.php +++ b/extensions/swiftmailer/yii/swiftmailer/Message.php @@ -48,6 +48,14 @@ class Message extends BaseMessage $this->getSwiftMessage()->setReplyTo($from); } + /** + * @return string from address of this message. + */ + public function getFrom() + { + return $this->getSwiftMessage()->getFrom(); + } + /** * @inheritdoc */ @@ -56,6 +64,14 @@ class Message extends BaseMessage $this->getSwiftMessage()->setTo($to); } + /** + * @return array To addresses of this message. + */ + public function getTo() + { + return $this->getSwiftMessage()->getTo(); + } + /** * @inheritdoc */ @@ -64,6 +80,14 @@ class Message extends BaseMessage $this->getSwiftMessage()->setCc($cc); } + /** + * @return array Cc address of this message. + */ + public function getCc() + { + return $this->getSwiftMessage()->getCc(); + } + /** * @inheritdoc */ @@ -72,6 +96,14 @@ class Message extends BaseMessage $this->getSwiftMessage()->setBcc($bcc); } + /** + * @return array Bcc addresses of this message. + */ + public function getBcc() + { + return $this->getSwiftMessage()->getBcc(); + } + /** * @inheritdoc */ @@ -80,6 +112,14 @@ class Message extends BaseMessage $this->getSwiftMessage()->setSubject($subject); } + /** + * @return string the subject of this message. + */ + public function getSubject() + { + return $this->getSwiftMessage()->getSubject(); + } + /** * @inheritdoc */ @@ -123,4 +163,12 @@ class Message extends BaseMessage $attachment = \Swift_Attachment::newInstance($content, $fileName, $contentType); $this->getSwiftMessage()->attach($attachment); } + + /** + * @inheritdoc + */ + public function __toString() + { + return $this->getSwiftMessage()->toString(); + } } \ No newline at end of file diff --git a/framework/yii/mail/MessageInterface.php b/framework/yii/mail/MessageInterface.php index 28223a4d43..48a4f10a64 100644 --- a/framework/yii/mail/MessageInterface.php +++ b/framework/yii/mail/MessageInterface.php @@ -113,4 +113,11 @@ interface MessageInterface * @return string string the rendering result */ public function render($view, $params = []); + + /** + * String output. + * This is PHP magic method that returns string representation of an object. + * @return string the string representation of the object + */ + public function __toString(); } \ No newline at end of file diff --git a/tests/unit/framework/mail/BaseMailerTest.php b/tests/unit/framework/mail/BaseMailerTest.php index 95bd836a21..e80ca0c0ba 100644 --- a/tests/unit/framework/mail/BaseMailerTest.php +++ b/tests/unit/framework/mail/BaseMailerTest.php @@ -188,4 +188,9 @@ class Message extends BaseMessage public function addHtml($html) {} public function attachContentAsFile($content, $fileName, $contentType = 'application/octet-stream') {} + + public function __toString() + { + return get_class($this); + } } \ No newline at end of file