-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[GH-28] Allow setting message streams transport-wide or per message #29
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,13 @@ class Transport implements Swift_Transport { | |
*/ | ||
protected $serverToken; | ||
|
||
/** | ||
* The Postmark Message Stream Identifier | ||
* | ||
* @var string|null | ||
*/ | ||
protected $messageStream; | ||
|
||
/** | ||
* @var \Swift_Events_EventDispatcher | ||
*/ | ||
|
@@ -28,11 +35,13 @@ class Transport implements Swift_Transport { | |
/** | ||
* Create a new Postmark transport instance. | ||
* | ||
* @param string $serverToken The API token for the server from which you will send mail. | ||
* @param string $serverToken The API token for the server from which you will send mail. | ||
* @param string $messageStream The name of the broadcast stream or the default if not provided | ||
* @return void | ||
*/ | ||
public function __construct($serverToken) { | ||
public function __construct($serverToken, $messageStream = null) { | ||
$this->serverToken = $serverToken; | ||
$this->messageStream = $messageStream; | ||
$this->version = phpversion(); | ||
$this->os = PHP_OS; | ||
$this->_eventDispatcher = \Swift_DependencyContainer::getInstance()->lookup('transport.eventdispatcher'); | ||
|
@@ -175,6 +184,8 @@ private function getMessagePayload(Swift_Mime_SimpleMessage $message) { | |
$this->processHeaders($payload, $message); | ||
} | ||
|
||
$this->processMessageStream($payload, $message); | ||
|
||
return $payload; | ||
} | ||
|
||
|
@@ -297,6 +308,22 @@ private function processHeaders(&$payload, $message) { | |
$payload['Headers'] = $headers; | ||
} | ||
|
||
/** | ||
* Applies the message stream into the API payload. | ||
* | ||
* @param array $payload | ||
* @param Swift_Mime_SimpleMessage $message | ||
* @return void | ||
*/ | ||
private function processMessageStream(&$payload, $message) | ||
{ | ||
if ($message->getHeaders() && $message->getHeaders()->has('X-PM-Message-Stream')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I saw the discussion in #20 about not adding special handling and detecting this in the API instead. However in this csae its necessary, if you have a message stream set as default, then it would be present in the API request, and probably not overwritten by the header that is sent as well. |
||
$payload['MessageStream'] = $message->getHeaders()->get('X-PM-Message-Stream', 0)->getFieldBody(); | ||
} else if ($this->messageStream !== NULL) { | ||
$payload['MessageStream'] = $this->messageStream; | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't make anything
private
, you don't know in what ways other users/customers need to customize things.See also #33
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The methods in this code are all mostly private, i keep to the existing style. No need to combine #33 into this here.