Browse Source

Added `yii\swiftmailer\Message::setHeaders()`

tags/2.0.7
Klimov Paul 8 years ago
parent
commit
c86c5ee246
  1. 1
      CHANGELOG.md
  2. 15
      Message.php
  3. 8
      tests/MessageTest.php

1
CHANGELOG.md

@ -5,6 +5,7 @@ Yii Framework 2 swiftmailer extension Change Log
----------------------- -----------------------
- Enh #37: `yii\swiftmailer\Logger` now chooses logging level depending on incoming entry format (klimov-paul) - Enh #37: `yii\swiftmailer\Logger` now chooses logging level depending on incoming entry format (klimov-paul)
- Enh #40: Added `yii\swiftmailer\Message::setHeaders()` allowing to setup custom headers in batch (klimov-paul)
2.0.6 September 09, 2016 2.0.6 September 09, 2016

15
Message.php

@ -20,6 +20,7 @@ use yii\mail\BaseMessage;
* *
* @method Mailer getMailer() returns mailer instance. * @method Mailer getMailer() returns mailer instance.
* *
* @property array $headers Custom header values of the message. This property is write-only.
* @property int $priority Priority value as integer in range: `1..5`, where 1 is the highest priority and * @property int $priority Priority value as integer in range: `1..5`, where 1 is the highest priority and
* 5 is the lowest. * 5 is the lowest.
* @property string $readReceiptTo Receipt receive email addresses. Note that the type of this property * @property string $readReceiptTo Receipt receive email addresses. Note that the type of this property
@ -479,6 +480,20 @@ class Message extends BaseMessage
return $headers; return $headers;
} }
/**
* Sets custom header values to the message.
* @param array $headers headers in format: `[name => value]`.
* @return $this self reference.
* @since 2.0.7
*/
public function setHeaders($headers)
{
foreach ($headers as $name => $value) {
$this->setHeader($name, $value);
}
return $this;
}
// SwiftMessage shortcuts : // SwiftMessage shortcuts :
/** /**

8
tests/MessageTest.php

@ -498,5 +498,13 @@ U41eAdnQ3dDGzUNedIJkSh6Z0A4VMZIEOag9hPNYqQXZBQgfobvPKw==
$this->assertEquals(['foo'], $message->getHeader('Some')); $this->assertEquals(['foo'], $message->getHeader('Some'));
$message->setHeader('Multiple', ['value1', 'value2']); $message->setHeader('Multiple', ['value1', 'value2']);
$this->assertEquals(['value1', 'value2'], $message->getHeader('Multiple')); $this->assertEquals(['value1', 'value2'], $message->getHeader('Multiple'));
$message = $this->createTestMessage()
->setHeaders([
'Some' => 'foo',
'Multiple' => ['value1', 'value2'],
]);
$this->assertEquals(['foo'], $message->getHeader('Some'));
$this->assertEquals(['value1', 'value2'], $message->getHeader('Multiple'));
} }
} }

Loading…
Cancel
Save