Last active
April 9, 2019 21:02
-
-
Save drakakisgeo/1bd4ca1bf9742b026d62622882c2e72b to your computer and use it in GitHub Desktop.
Postmark Trait for Laravel Mailable - (Support for Tag and Meta)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Billit\Traits; | |
trait Postmarkable | |
{ | |
/** | |
* @param array $tags | |
*/ | |
public function setTag(string $tag): void | |
{ | |
$this->tag = $tag; | |
} | |
/** | |
* @param array $meta | |
*/ | |
public function setMeta(array $meta): void | |
{ | |
$this->meta = $meta; | |
} | |
private function addPostmarkHeaders() | |
{ | |
if ($this->tag || sizeof($this->meta) > 0) { | |
$this->withSwiftMessage(function ($message) { | |
if ($this->tag) { | |
$message->getHeaders()->addTextHeader('X-PM-Tag', $this->tag); | |
} | |
if (sizeof($this->meta) > 0) { | |
foreach ($this->meta as $key=>$value) { | |
$message->getHeaders()->addTextHeader('X-PM-Metadata-'.$key, $value); | |
} | |
} | |
}); | |
} | |
return $this; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Billit\Traits; | |
trait Postmarkable | |
{ | |
/** | |
* @param array $tags | |
*/ | |
public function setTag(array $tag): void | |
{ | |
$this->tag = $tag; | |
} | |
/** | |
* @param array $meta | |
*/ | |
public function setMeta(array $meta): void | |
{ | |
$this->meta = $meta; | |
} | |
private function addPostmarkHeaders() | |
{ | |
if ($this->tag || sizeof($this->meta) > 0) { | |
$this->withSwiftMessage(function ($message) { | |
if ($this->tag) { | |
$message->getHeaders()->addTextHeader('X-PM-Tag', $this->tag); | |
} | |
if (sizeof($this->meta) > 0) { | |
foreach ($this->meta as $key=>$value) { | |
$message->getHeaders()->addTextHeader('X-PM-Metadata-'.$key, $value); | |
} | |
} | |
}); | |
} | |
return $this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment