Skip to content
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

[5.3] Allow SparkPost transport transmission metadata to be set at runtime #16838

Merged
merged 4 commits into from
Dec 20, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion src/Illuminate/Mail/Transport/SparkPostTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,28 @@ class SparkPostTransport extends Transport
*/
protected $options = [];

/**
* Transmission metadata.
*
* @var array
*/
protected $metadata = [];

/**
* Create a new SparkPost transport instance.
*
* @param \GuzzleHttp\ClientInterface $client
* @param string $key
* @param array $options
* @param array $metadata
* @return void
*/
public function __construct(ClientInterface $client, $key, $options = [])
public function __construct(ClientInterface $client, $key, $options = [], $metadata = [])
{
$this->key = $key;
$this->client = $client;
$this->options = $options;
$this->metadata = $metadata;
}

/**
Expand Down Expand Up @@ -70,6 +79,10 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null)
$options['json']['options'] = $this->options;
}

if ($this->metadata) {
$options['json']['metadata'] = $this->metadata;
}

$this->client->post('https://api.sparkpost.com/api/v1/transmissions', $options);

$this->sendPerformed($message);
Expand Down Expand Up @@ -149,4 +162,25 @@ public function setOptions(array $options)
{
return $this->options = $options;
}

/**
* Set the transmission metadata being used by the transport.
*
* @param array $metadata
* @return array
*/
public function setMetadata(array $metadata)
{
return $this->metadata = $metadata;
}

/**
* Get the transmission metadata being used by the transport.
*
* @return string
*/
public function getMetadata()
{
return $this->metadata;
}
}