Skip to content

Commit b1e8725

Browse files
authored
Merge pull request #2545 from BinarCode/templates
Placehlder replacers.
2 parents 0b88b07 + 2bc12dc commit b1e8725

22 files changed

+569
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ output
77
docs/node_modules
88
docs/.vuepress/dist
99
.php_cs.cache
10+
.phpunit.result.cache

.php_cs.cache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"php":"7.4.7","version":"2.16.4","indent":" ","lineEnding":"\n","rules":{"blank_line_after_namespace":true,"braces":true,"class_definition":true,"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline","keep_multiple_spaces_after_comma":true},"no_break_comment":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":true,"encoding":true,"full_opening_tag":true,"array_syntax":{"syntax":"short"},"ordered_imports":{"sortAlgorithm":"alpha"},"no_unused_imports":true,"not_operator_with_successor_space":true,"trailing_comma_in_multiline_array":true,"phpdoc_scalar":true,"unary_operator_spaces":true,"binary_operator_spaces":true,"blank_line_before_statement":{"statements":["break","continue","declare","return","throw","try"]},"phpdoc_single_line_var_spacing":true,"phpdoc_var_without_name":true},"hashes":{"src\/Replacers\/Replacer.php":253370695,"src\/Replacers\/SampleReplacer.php":151931666,"src\/Replacers\/PlaceholdersReplacer.php":3106943315,"src\/Replacers\/Concerns\/ReplaceModelAttributes.php":2894682531,"src\/LaravelMailator.php":2400267913,"src\/Constraints\/SendScheduleConstraint.php":1560191468,"src\/Scheduler.php":2350220382,"src\/Models\/MailTemplateable.php":2389293087,"src\/Models\/MailatorLog.php":2389082039,"src\/Models\/MailTemplate.php":1145643679,"src\/Models\/MailTemplatePlaceholder.php":1599018622,"src\/Models\/Concerns\/WithUuid.php":2073956148,"src\/Models\/MailatorSchedule.php":1576939518,"src\/LaravelMailatorFacade.php":979572002,"src\/Actions\/SendMailAction.php":845081293,"src\/Actions\/PersonalizeMailAction.php":762917368,"src\/Exceptions\/InstanceException.php":3148717182,"src\/Exceptions\/InvalidTemplateException.php":168403369,"src\/Events\/ScheduleMailSentEvent.php":1474721612,"src\/Support\/WithMailTemplate.php":1308936561,"src\/Jobs\/SendMailJob.php":2514949383,"src\/LaravelMailatorServiceProvider.php":2856073029,"tests\/Feature\/Models\/MailTemplateTest.php":2201463783,"tests\/Feature\/Models\/MailatorScheduleTest.php":2522577137,"tests\/TestCase.php":3224517909,"tests\/Fixtures\/WelcomeMailatorMailable.php":2648011873,"tests\/Fixtures\/User.php":2452662883,"tests\/Fixtures\/BeforeInvoiceExpiresConstraint.php":3604949673,"tests\/Fixtures\/SingleSendingCondition.php":1762964641,"tests\/Fixtures\/InvoiceReminderMailable.php":2978038343,"tests\/database\/factories\/MailatorScheduleFactory.php":1183362450}}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020
"php": "^7.4",
2121
"illuminate/support": "^7.0",
2222
"opis/closure": "^3.5",
23-
"spatie/test-time": "^1.2"
23+
"tijsverkoyen/css-to-inline-styles": "^2.2"
2424
},
2525
"require-dev": {
2626
"friendsofphp/php-cs-fixer": "^2.16",
2727
"orchestra/testbench": "^5.0",
2828
"phpunit/phpunit": "^9.0",
29+
"spatie/test-time": "^1.2",
2930
"psalm/plugin-laravel": "^1.2",
3031
"vimeo/psalm": "^3.11"
3132
},

config/mailator.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,18 @@
2929
],
3030

3131
'log_model' => Binarcode\LaravelMailator\Models\MailatorLog::class,
32+
33+
'templates' => [
34+
/**
35+
> The email layout, used to wrap the template.
36+
*/
37+
'laravel-mailator::mails.template_layout' => 'laravel-mailator::mails.template_layout',
38+
39+
/**
40+
> The default list with replacers for the template.
41+
*/
42+
'replacers' => [
43+
Binarcode\LaravelMailator\Replacers\SampleReplacer::class,
44+
],
45+
],
3246
];

database/migrations/create_mailator_tables.php.stub

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,34 @@ class CreateMailatorTables extends Migration
5656
->references('id')
5757
->on(config('mailator.schedulers_table_name', 'mailator_schedulers'));
5858
});
59+
60+
Schema::create('mail_templates', function (Blueprint $table) {
61+
$table->id();
62+
$table->uuid('uuid');
63+
64+
$table->string('name')->nullable();
65+
$table->string('from_email')->nullable();
66+
$table->string('from_name')->nullable();
67+
$table->string('subject')->nullable();
68+
69+
$table->longText('html')->nullable();
70+
$table->longText('email_html')->nullable();
71+
$table->longText('webview_html')->nullable();
72+
73+
$table->string('mailable_class')->nullable();
74+
$table->timestamps();
75+
});
76+
77+
Schema::create('mail_template_placeholders', function (Blueprint $table) {
78+
$table->id();
79+
$table->foreignId('mail_template_id')->constrained('mail_templates')->cascadeOnDelete();
80+
$table->string('name');
81+
$table->string('description');
82+
$table->json('meta')->nullable();
83+
$table->timestamps();
84+
85+
/** * Indexes */
86+
$table->index('mail_template_id');
87+
});
5988
}
6089
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{ $template->getContent() ?? '' }}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml">
3+
<head>
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
5+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6+
</head>
7+
<body>
8+
<style>
9+
@media only screen and (max-width: 600px) {
10+
.inner-body {
11+
width: 100% !important;
12+
}
13+
14+
.footer {
15+
width: 100% !important;
16+
}
17+
}
18+
19+
@media only screen and (max-width: 500px) {
20+
.button {
21+
width: 100% !important;
22+
}
23+
}
24+
</style>
25+
26+
<table class="wrapper" width="100%" cellpadding="0" cellspacing="0" role="presentation">
27+
<tr>
28+
<td align="center">
29+
<table class="content" width="100%" cellpadding="0" cellspacing="0" role="presentation">
30+
{{ $header ?? '' }}
31+
32+
<!-- Email Body -->
33+
<tr>
34+
<td class="body" width="100%" cellpadding="0" cellspacing="0">
35+
<table class="inner-body" align="center" width="570" cellpadding="0" cellspacing="0" role="presentation">
36+
<!-- Body content -->
37+
<tr>
38+
<td class="content-cell">
39+
40+
{{ $template->getContent() ?? '' }}
41+
42+
{{ $subcopy ?? '' }}
43+
</td>
44+
</tr>
45+
</table>
46+
</td>
47+
</tr>
48+
49+
{{ $footer ?? '' }}
50+
</table>
51+
</td>
52+
</tr>
53+
</table>
54+
</body>
55+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Explicabo iusto laudantium molestias quae ratione vitae? Architecto dignissimos inventore laudantium omnis? Beatae blanditiis ex neque obcaecati quos voluptate voluptatem. Ducimus, quo.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Binarcode\LaravelMailator\Actions;
4+
5+
use Binarcode\LaravelMailator\Models\MailTemplateable;
6+
use Binarcode\LaravelMailator\Replacers\Replacer;
7+
8+
class PersonalizeMailAction
9+
{
10+
public function execute($html, MailTemplateable $template, array $replacers): string
11+
{
12+
return collect($replacers)
13+
->filter(fn (object $class) => $class instanceof Replacer)
14+
->reduce(fn (string $html, Replacer $replacer) => $replacer->replace($html, $template), $html);
15+
}
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Binarcode\LaravelMailator\Exceptions;
4+
5+
use Binarcode\LaravelMailator\Models\MailTemplateable;
6+
use Exception;
7+
8+
class InvalidTemplateException extends Exception
9+
{
10+
public static function throw(string $actual)
11+
{
12+
return new static('Expected instance of ' . MailTemplateable::class . ", given [$actual].");
13+
}
14+
}

0 commit comments

Comments
 (0)