Browse Source

'yii\mail\MessageInterface' methods 'addText()' and 'addHtml()' removed.

tags/2.0.0-beta
Paul Klimov 11 years ago
parent
commit
1d0891f0f6
  1. 54
      extensions/swiftmailer/yii/swiftmailer/Message.php
  2. 12
      framework/yii/mail/MessageInterface.php
  3. 4
      tests/unit/extensions/swiftmailer/MessageTest.php
  4. 4
      tests/unit/framework/mail/BaseMailerTest.php

54
extensions/swiftmailer/yii/swiftmailer/Message.php

@ -125,7 +125,7 @@ class Message extends BaseMessage
*/ */
public function setText($text) public function setText($text)
{ {
$this->getSwiftMessage()->setBody($text, 'text/plain'); $this->setBody($text, 'text/plain');
} }
/** /**
@ -133,23 +133,51 @@ class Message extends BaseMessage
*/ */
public function setHtml($html) public function setHtml($html)
{ {
$this->getSwiftMessage()->setBody($html, 'text/html'); $this->setBody($html, 'text/html');
} }
/** /**
* @inheritdoc * Sets the message body.
* If body is already set and its content type matches given one, it will
* be overridden, if content type miss match the multipart message will be composed.
* @param string $body body content.
* @param string $contentType body content type.
*/ */
public function addText($text) protected function setBody($body, $contentType)
{ {
$this->getSwiftMessage()->addPart($text, 'text/plain'); $message = $this->getSwiftMessage();
} $oldBody = $message->getBody();
if (empty($oldBody)) {
/** $parts = $message->getChildren();
* @inheritdoc $partFound = false;
*/ foreach ($parts as $key => $part) {
public function addHtml($html) if (!($part instanceof \Swift_Mime_Attachment)) {
{ /* @var $part \Swift_Mime_MimePart */
$this->getSwiftMessage()->addPart($html, 'text/html'); if ($part->getContentType() == $contentType) {
unset($parts[$key]);
$partFound = true;
break;
}
}
}
if ($partFound) {
reset($parts);
$message->setChildren($parts);
$message->addPart($body, $contentType);
} else {
$message->setBody($body, $contentType);
}
} else {
$oldContentType = $message->getContentType();
if ($oldContentType == $contentType) {
$message->setBody($body, $contentType);
} else {
$message->setBody(null);
$message->setContentType(null);
$message->addPart($oldBody, $oldContentType);
$message->addPart($body, $contentType);
}
}
} }
/** /**

12
framework/yii/mail/MessageInterface.php

@ -70,18 +70,6 @@ interface MessageInterface
public function setHtml($html); public function setHtml($html);
/** /**
* Add message plain text content part.
* @param string $text message plain text content.
*/
public function addText($text);
/**
* Add message HTML content part.
* @param string $html message HTML content.
*/
public function addHtml($html);
/**
* Attach specified content as file for the email message. * Attach specified content as file for the email message.
* @param string $content attachment file content. * @param string $content attachment file content.
* @param array $options options for embed file. Valid options are: * @param array $options options for embed file. Valid options are:

4
tests/unit/extensions/swiftmailer/MessageTest.php

@ -182,8 +182,8 @@ class MessageTest extends VendorTestCase
$message->setTo($this->testEmailReceiver); $message->setTo($this->testEmailReceiver);
$message->setFrom('someuser@somedomain.com'); $message->setFrom('someuser@somedomain.com');
$message->setSubject('Yii Swift Alternative Body Test'); $message->setSubject('Yii Swift Alternative Body Test');
$message->addHtml('<b>Yii Swift</b> test HTML body'); $message->setHtml('<b>Yii Swift</b> test HTML body');
$message->addText('Yii Swift test plain text body'); $message->setText('Yii Swift test plain text body');
$this->assertTrue($message->send()); $this->assertTrue($message->send());
} }
} }

4
tests/unit/framework/mail/BaseMailerTest.php

@ -182,10 +182,6 @@ class Message extends BaseMessage
public function setHtml($html) {} public function setHtml($html) {}
public function addText($text) {}
public function addHtml($html) {}
public function attachContent($content, array $options = []) {} public function attachContent($content, array $options = []) {}
public function attachFile($fileName, array $options = []) {} public function attachFile($fileName, array $options = []) {}

Loading…
Cancel
Save