-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from mettle/feature/message-subject-tags
Feature/message subject tags
- Loading branch information
Showing
9 changed files
with
221 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sendportal\Base\Services\Content; | ||
|
||
use Sendportal\Base\Models\Message; | ||
use Sendportal\Base\Traits\NormalizeTags; | ||
|
||
class MergeSubjectService | ||
{ | ||
use NormalizeTags; | ||
|
||
public function handle(Message $message): string | ||
{ | ||
$messageSubject = $this->compileTags($message); | ||
|
||
return $this->mergeSubscriberTags($messageSubject, $message); | ||
} | ||
|
||
protected function compileTags(Message $message): string | ||
{ | ||
$tags = [ | ||
'email', | ||
'first_name', | ||
'last_name', | ||
]; | ||
|
||
$messageSubject = $message->subject; | ||
|
||
foreach ($tags as $tag) { | ||
$messageSubject = $this->normalizeTags($messageSubject, $tag); | ||
} | ||
|
||
return $messageSubject; | ||
} | ||
|
||
protected function mergeSubscriberTags(string $messageSubject, Message $message): string | ||
{ | ||
$tags = [ | ||
'email' => $message->recipient_email, | ||
'first_name' => $message->subscriber ? $message->subscriber->first_name : '', | ||
'last_name' => $message->subscriber ? $message->subscriber->last_name : '', | ||
]; | ||
|
||
foreach ($tags as $key => $replace) { | ||
$messageSubject = str_ireplace('{{' . $key . '}}', $replace, $messageSubject); | ||
} | ||
|
||
return $messageSubject; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.