@@ -19,7 +19,7 @@ |
||
19 | 19 | * specific view to be rendered. |
20 | 20 | */ |
21 | 21 | 'view_root_locations' => [ |
22 | - 'default' => __DIR__ . '/../views', |
|
22 | + 'default' => __DIR__.'/../views', |
|
23 | 23 | ], |
24 | 24 | |
25 | 25 | /* |
@@ -16,187 +16,187 @@ |
||
16 | 16 | * `ConfigInterface` to the `ChainMail` constructor. |
17 | 17 | */ |
18 | 18 | return [ |
19 | - /* |
|
19 | + /* |
|
20 | 20 | * Root location that contains the view files to be rendered. These are |
21 | 21 | * referenced by the individual sections & templates when choosing a |
22 | 22 | * specific view to be rendered. |
23 | 23 | */ |
24 | - 'view_root_locations' => [ |
|
25 | - 'default' => __DIR__ . '/../views', |
|
26 | - ], |
|
24 | + 'view_root_locations' => [ |
|
25 | + 'default' => __DIR__ . '/../views', |
|
26 | + ], |
|
27 | 27 | |
28 | - /* |
|
28 | + /* |
|
29 | 29 | * Type of view rendering system to use. |
30 | 30 | */ |
31 | - 'view_type' => 'PHPView', |
|
31 | + 'view_type' => 'PHPView', |
|
32 | 32 | |
33 | - /* |
|
33 | + /* |
|
34 | 34 | * The default template to when none is specified. |
35 | 35 | */ |
36 | - 'default_template' => 'BasicTemplate', |
|
36 | + 'default_template' => 'BasicTemplate', |
|
37 | 37 | |
38 | - /* |
|
38 | + /* |
|
39 | 39 | * The formats in which an email can be rendered. |
40 | 40 | * Each format needs a `MailInterface` implementation, a |
41 | 41 | * `ValidatorInterface` implementation, as well as a `SanitizerInterface` |
42 | 42 | * implementation. |
43 | 43 | */ |
44 | - 'formats' => [ |
|
44 | + 'formats' => [ |
|
45 | 45 | |
46 | - /* |
|
46 | + /* |
|
47 | 47 | * The `html` format should be the default format when using responsive |
48 | 48 | * emails. |
49 | 49 | */ |
50 | - 'html' => [ |
|
51 | - 'mail' => 'HTMLMail', |
|
52 | - 'validator' => 'HTMLValidator', |
|
53 | - 'sanitizer' => 'HTMLSanitizer', |
|
54 | - ], |
|
50 | + 'html' => [ |
|
51 | + 'mail' => 'HTMLMail', |
|
52 | + 'validator' => 'HTMLValidator', |
|
53 | + 'sanitizer' => 'HTMLSanitizer', |
|
54 | + ], |
|
55 | 55 | |
56 | - /* |
|
56 | + /* |
|
57 | 57 | * The `text` format is meant to be used a as a fallback, and can also |
58 | 58 | * be sent as backup content embedded within HTML emails. |
59 | 59 | */ |
60 | - 'text' => [ |
|
61 | - 'mail' => 'TextMail', |
|
62 | - 'validator' => 'TextValidator', |
|
63 | - 'sanitizer' => 'TextSanitizer', |
|
64 | - ], |
|
65 | - ], |
|
60 | + 'text' => [ |
|
61 | + 'mail' => 'TextMail', |
|
62 | + 'validator' => 'TextValidator', |
|
63 | + 'sanitizer' => 'TextSanitizer', |
|
64 | + ], |
|
65 | + ], |
|
66 | 66 | |
67 | - /* |
|
67 | + /* |
|
68 | 68 | * The `MailInterface` implementations that are provided. |
69 | 69 | */ |
70 | - 'mails' => [ |
|
71 | - 'HTMLMail' => [ |
|
72 | - 'class_name' => '\BrightNucleus\ChainMail\Mail\HTMLMail', |
|
73 | - ], |
|
74 | - 'TextMail' => [ |
|
75 | - 'class_name' => '\BrightNucleus\ChainMail\Mail\TextMail', |
|
76 | - ], |
|
77 | - ], |
|
70 | + 'mails' => [ |
|
71 | + 'HTMLMail' => [ |
|
72 | + 'class_name' => '\BrightNucleus\ChainMail\Mail\HTMLMail', |
|
73 | + ], |
|
74 | + 'TextMail' => [ |
|
75 | + 'class_name' => '\BrightNucleus\ChainMail\Mail\TextMail', |
|
76 | + ], |
|
77 | + ], |
|
78 | 78 | |
79 | - /* |
|
79 | + /* |
|
80 | 80 | * The `ValidatorInterface` implementations that are provided. |
81 | 81 | */ |
82 | - 'validators' => [ |
|
83 | - 'HTMLValidator' => [ |
|
84 | - 'class_name' => '\BrightNucleus\ChainMail\Validator\HTMLValidator', |
|
85 | - ], |
|
86 | - 'TextValidator' => [ |
|
87 | - 'class_name' => '\BrightNucleus\ChainMail\Validator\TextValidator', |
|
88 | - ], |
|
89 | - ], |
|
82 | + 'validators' => [ |
|
83 | + 'HTMLValidator' => [ |
|
84 | + 'class_name' => '\BrightNucleus\ChainMail\Validator\HTMLValidator', |
|
85 | + ], |
|
86 | + 'TextValidator' => [ |
|
87 | + 'class_name' => '\BrightNucleus\ChainMail\Validator\TextValidator', |
|
88 | + ], |
|
89 | + ], |
|
90 | 90 | |
91 | - /* |
|
91 | + /* |
|
92 | 92 | * The `SanitizerInterface` implementations that are provided. |
93 | 93 | */ |
94 | - 'sanitizers' => [ |
|
95 | - 'HTMLSanitizer' => [ |
|
96 | - 'class_name' => '\BrightNucleus\ChainMail\Sanitizer\HTMLSanitizer', |
|
97 | - ], |
|
98 | - 'TextSanitizer' => [ |
|
99 | - 'class_name' => '\BrightNucleus\ChainMail\Sanitizer\TextSanitizer', |
|
100 | - ], |
|
101 | - ], |
|
94 | + 'sanitizers' => [ |
|
95 | + 'HTMLSanitizer' => [ |
|
96 | + 'class_name' => '\BrightNucleus\ChainMail\Sanitizer\HTMLSanitizer', |
|
97 | + ], |
|
98 | + 'TextSanitizer' => [ |
|
99 | + 'class_name' => '\BrightNucleus\ChainMail\Sanitizer\TextSanitizer', |
|
100 | + ], |
|
101 | + ], |
|
102 | 102 | |
103 | - /* |
|
103 | + /* |
|
104 | 104 | * The `ViewInterface` implementations that are provided. |
105 | 105 | */ |
106 | - 'view_types' => [ |
|
107 | - 'PHPView' => [ |
|
108 | - 'class_name' => '\BrightNucleus\ChainMail\View\PHPView', |
|
109 | - ], |
|
110 | - ], |
|
106 | + 'view_types' => [ |
|
107 | + 'PHPView' => [ |
|
108 | + 'class_name' => '\BrightNucleus\ChainMail\View\PHPView', |
|
109 | + ], |
|
110 | + ], |
|
111 | 111 | |
112 | - /* |
|
112 | + /* |
|
113 | 113 | * The `TemplateInterface` implementations that are provided. |
114 | 114 | * |
115 | 115 | * Each template also defines what sections it intends to use, and what |
116 | 116 | * view it intends to use for rendering. |
117 | 117 | */ |
118 | - 'templates' => [ |
|
119 | - 'BasicTemplate' => [ |
|
120 | - 'class_name' => '\BrightNucleus\ChainMail\Template\GenericTemplate', |
|
121 | - 'sections' => [ |
|
122 | - 'HeaderSection', |
|
123 | - 'BodySection', |
|
124 | - 'FooterSection', |
|
125 | - ], |
|
126 | - 'view_name' => 'GenericTemplate', |
|
127 | - 'view_location' => 'default', |
|
128 | - ], |
|
129 | - 'HeroTemplate' => [ |
|
130 | - 'class_name' => '\BrightNucleus\ChainMail\Template\GenericTemplate', |
|
131 | - 'sections' => [ |
|
132 | - 'HeaderSection', |
|
133 | - 'HeroSection', |
|
134 | - 'BodySection', |
|
135 | - 'FooterSection', |
|
136 | - ], |
|
137 | - 'view_name' => 'GenericTemplate', |
|
138 | - 'view_location' => 'default', |
|
139 | - ], |
|
140 | - 'SidebarTemplate' => [ |
|
141 | - 'class_name' => '\BrightNucleus\ChainMail\Template\GenericTemplate', |
|
142 | - 'sections' => [ |
|
143 | - 'HeaderSection', |
|
144 | - 'BodySection', |
|
145 | - 'SidebarSection', |
|
146 | - 'FooterSection', |
|
147 | - ], |
|
148 | - 'view_name' => 'GenericTemplate', |
|
149 | - 'view_location' => 'default', |
|
150 | - ], |
|
151 | - 'HeroSidebarTemplate' => [ |
|
152 | - 'class_name' => '\BrightNucleus\ChainMail\Template\GenericTemplate', |
|
153 | - 'sections' => [ |
|
154 | - 'HeaderSection', |
|
155 | - 'HeroSection', |
|
156 | - 'BodySection', |
|
157 | - 'SidebarSection', |
|
158 | - 'FooterSection', |
|
159 | - ], |
|
160 | - 'view_name' => 'GenericTemplate', |
|
161 | - 'view_location' => 'default', |
|
162 | - ], |
|
163 | - ], |
|
118 | + 'templates' => [ |
|
119 | + 'BasicTemplate' => [ |
|
120 | + 'class_name' => '\BrightNucleus\ChainMail\Template\GenericTemplate', |
|
121 | + 'sections' => [ |
|
122 | + 'HeaderSection', |
|
123 | + 'BodySection', |
|
124 | + 'FooterSection', |
|
125 | + ], |
|
126 | + 'view_name' => 'GenericTemplate', |
|
127 | + 'view_location' => 'default', |
|
128 | + ], |
|
129 | + 'HeroTemplate' => [ |
|
130 | + 'class_name' => '\BrightNucleus\ChainMail\Template\GenericTemplate', |
|
131 | + 'sections' => [ |
|
132 | + 'HeaderSection', |
|
133 | + 'HeroSection', |
|
134 | + 'BodySection', |
|
135 | + 'FooterSection', |
|
136 | + ], |
|
137 | + 'view_name' => 'GenericTemplate', |
|
138 | + 'view_location' => 'default', |
|
139 | + ], |
|
140 | + 'SidebarTemplate' => [ |
|
141 | + 'class_name' => '\BrightNucleus\ChainMail\Template\GenericTemplate', |
|
142 | + 'sections' => [ |
|
143 | + 'HeaderSection', |
|
144 | + 'BodySection', |
|
145 | + 'SidebarSection', |
|
146 | + 'FooterSection', |
|
147 | + ], |
|
148 | + 'view_name' => 'GenericTemplate', |
|
149 | + 'view_location' => 'default', |
|
150 | + ], |
|
151 | + 'HeroSidebarTemplate' => [ |
|
152 | + 'class_name' => '\BrightNucleus\ChainMail\Template\GenericTemplate', |
|
153 | + 'sections' => [ |
|
154 | + 'HeaderSection', |
|
155 | + 'HeroSection', |
|
156 | + 'BodySection', |
|
157 | + 'SidebarSection', |
|
158 | + 'FooterSection', |
|
159 | + ], |
|
160 | + 'view_name' => 'GenericTemplate', |
|
161 | + 'view_location' => 'default', |
|
162 | + ], |
|
163 | + ], |
|
164 | 164 | |
165 | - /* |
|
165 | + /* |
|
166 | 166 | * The `SectionInterface` implementations that are provided. |
167 | 167 | * |
168 | 168 | * Each section also defines what view it intends to use for rendering. |
169 | 169 | */ |
170 | - 'sections' => [ |
|
171 | - 'HeaderSection' => [ |
|
172 | - 'css_class' => 'header', |
|
173 | - 'class_name' => '\BrightNucleus\ChainMail\Section\GenericSection', |
|
174 | - 'view_name' => 'GenericSection', |
|
175 | - 'view_location' => 'default', |
|
176 | - ], |
|
177 | - 'BodySection' => [ |
|
178 | - 'css_class' => 'body', |
|
179 | - 'class_name' => '\BrightNucleus\ChainMail\Section\GenericSection', |
|
180 | - 'view_name' => 'GenericSection', |
|
181 | - 'view_location' => 'default', |
|
182 | - ], |
|
183 | - 'FooterSection' => [ |
|
184 | - 'css_class' => 'footer', |
|
185 | - 'class_name' => '\BrightNucleus\ChainMail\Section\GenericSection', |
|
186 | - 'view_name' => 'GenericSection', |
|
187 | - 'view_location' => 'default', |
|
188 | - ], |
|
189 | - 'HeroSection' => [ |
|
190 | - 'css_class' => 'hero', |
|
191 | - 'class_name' => '\BrightNucleus\ChainMail\Section\GenericSection', |
|
192 | - 'view_name' => 'GenericSection', |
|
193 | - 'view_location' => 'default', |
|
194 | - ], |
|
195 | - 'SidebarSection' => [ |
|
196 | - 'css_class' => 'sidebar', |
|
197 | - 'class_name' => '\BrightNucleus\ChainMail\Section\GenericSection', |
|
198 | - 'view_name' => 'GenericSection', |
|
199 | - 'view_location' => 'default', |
|
200 | - ], |
|
201 | - ], |
|
170 | + 'sections' => [ |
|
171 | + 'HeaderSection' => [ |
|
172 | + 'css_class' => 'header', |
|
173 | + 'class_name' => '\BrightNucleus\ChainMail\Section\GenericSection', |
|
174 | + 'view_name' => 'GenericSection', |
|
175 | + 'view_location' => 'default', |
|
176 | + ], |
|
177 | + 'BodySection' => [ |
|
178 | + 'css_class' => 'body', |
|
179 | + 'class_name' => '\BrightNucleus\ChainMail\Section\GenericSection', |
|
180 | + 'view_name' => 'GenericSection', |
|
181 | + 'view_location' => 'default', |
|
182 | + ], |
|
183 | + 'FooterSection' => [ |
|
184 | + 'css_class' => 'footer', |
|
185 | + 'class_name' => '\BrightNucleus\ChainMail\Section\GenericSection', |
|
186 | + 'view_name' => 'GenericSection', |
|
187 | + 'view_location' => 'default', |
|
188 | + ], |
|
189 | + 'HeroSection' => [ |
|
190 | + 'css_class' => 'hero', |
|
191 | + 'class_name' => '\BrightNucleus\ChainMail\Section\GenericSection', |
|
192 | + 'view_name' => 'GenericSection', |
|
193 | + 'view_location' => 'default', |
|
194 | + ], |
|
195 | + 'SidebarSection' => [ |
|
196 | + 'css_class' => 'sidebar', |
|
197 | + 'class_name' => '\BrightNucleus\ChainMail\Section\GenericSection', |
|
198 | + 'view_name' => 'GenericSection', |
|
199 | + 'view_location' => 'default', |
|
200 | + ], |
|
201 | + ], |
|
202 | 202 | ]; |
@@ -37,7 +37,7 @@ |
||
37 | 37 | |
38 | 38 | ob_start(); |
39 | 39 | |
40 | - include $this->viewLocation . '.php'; |
|
40 | + include $this->viewLocation.'.php'; |
|
41 | 41 | |
42 | 42 | return ob_get_clean(); |
43 | 43 | } |
@@ -22,24 +22,24 @@ |
||
22 | 22 | class PHPView extends AbstractView |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Render the current Renderable for a given context. |
|
27 | - * |
|
28 | - * @since 1.0.0 |
|
29 | - * |
|
30 | - * @param array $context The context in which to render the Renderable. |
|
31 | - * @param string|null $content Optional. The content that the view should |
|
32 | - * represent. |
|
33 | - * |
|
34 | - * @return string Rendered output of the Renderable. |
|
35 | - */ |
|
36 | - public function render(array $context, $content = null) |
|
37 | - { |
|
25 | + /** |
|
26 | + * Render the current Renderable for a given context. |
|
27 | + * |
|
28 | + * @since 1.0.0 |
|
29 | + * |
|
30 | + * @param array $context The context in which to render the Renderable. |
|
31 | + * @param string|null $content Optional. The content that the view should |
|
32 | + * represent. |
|
33 | + * |
|
34 | + * @return string Rendered output of the Renderable. |
|
35 | + */ |
|
36 | + public function render(array $context, $content = null) |
|
37 | + { |
|
38 | 38 | |
39 | - ob_start(); |
|
39 | + ob_start(); |
|
40 | 40 | |
41 | - include $this->viewLocation . '.php'; |
|
41 | + include $this->viewLocation . '.php'; |
|
42 | 42 | |
43 | - return ob_get_clean(); |
|
44 | - } |
|
43 | + return ob_get_clean(); |
|
44 | + } |
|
45 | 45 | } |
@@ -12,7 +12,7 @@ |
||
12 | 12 | namespace BrightNucleus\ChainMail; |
13 | 13 | |
14 | 14 | if ( ! $content) { |
15 | - return; |
|
15 | + return; |
|
16 | 16 | } |
17 | 17 | ?> |
18 | 18 | <div class="<?php echo $context['css_class']; ?>"><?php echo $content; ?></div> |
@@ -25,35 +25,35 @@ |
||
25 | 25 | abstract class AbstractView implements ViewInterface |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * Configuration Settings. |
|
30 | - * |
|
31 | - * @since 1.0.0 |
|
32 | - * |
|
33 | - * @var ConfigInterface |
|
34 | - */ |
|
35 | - protected $config; |
|
28 | + /** |
|
29 | + * Configuration Settings. |
|
30 | + * |
|
31 | + * @since 1.0.0 |
|
32 | + * |
|
33 | + * @var ConfigInterface |
|
34 | + */ |
|
35 | + protected $config; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Location of the view data. |
|
39 | - * |
|
40 | - * @since 1.0.0 |
|
41 | - * |
|
42 | - * @var 1.0.0 |
|
43 | - */ |
|
44 | - protected $viewLocation; |
|
37 | + /** |
|
38 | + * Location of the view data. |
|
39 | + * |
|
40 | + * @since 1.0.0 |
|
41 | + * |
|
42 | + * @var 1.0.0 |
|
43 | + */ |
|
44 | + protected $viewLocation; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Instantiate a View object. |
|
48 | - * |
|
49 | - * @since 1.0.0 |
|
50 | - * |
|
51 | - * @param ConfigInterface $config Configuration settings. |
|
52 | - * @param string $viewLocation Location of the View to render. |
|
53 | - */ |
|
54 | - public function __construct($config, $viewLocation) |
|
55 | - { |
|
56 | - $this->config = $config; |
|
57 | - $this->viewLocation = $viewLocation; |
|
58 | - } |
|
46 | + /** |
|
47 | + * Instantiate a View object. |
|
48 | + * |
|
49 | + * @since 1.0.0 |
|
50 | + * |
|
51 | + * @param ConfigInterface $config Configuration settings. |
|
52 | + * @param string $viewLocation Location of the View to render. |
|
53 | + */ |
|
54 | + public function __construct($config, $viewLocation) |
|
55 | + { |
|
56 | + $this->config = $config; |
|
57 | + $this->viewLocation = $viewLocation; |
|
58 | + } |
|
59 | 59 | } |
@@ -22,27 +22,27 @@ |
||
22 | 22 | class HTMLMail extends AbstractMail |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Set the format of the mail. |
|
27 | - * |
|
28 | - * @since 1.0.0 |
|
29 | - */ |
|
30 | - protected function setFormat() |
|
31 | - { |
|
32 | - $this->format = 'html'; |
|
33 | - } |
|
25 | + /** |
|
26 | + * Set the format of the mail. |
|
27 | + * |
|
28 | + * @since 1.0.0 |
|
29 | + */ |
|
30 | + protected function setFormat() |
|
31 | + { |
|
32 | + $this->format = 'html'; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Set the context of the renderer. |
|
37 | - * |
|
38 | - * @since 1.0.0 |
|
39 | - * |
|
40 | - * @param array $context Context to set/modify. |
|
41 | - * |
|
42 | - * @return array Updated context. |
|
43 | - */ |
|
44 | - protected function setContext(array $context) |
|
45 | - { |
|
46 | - return $context; |
|
47 | - } |
|
35 | + /** |
|
36 | + * Set the context of the renderer. |
|
37 | + * |
|
38 | + * @since 1.0.0 |
|
39 | + * |
|
40 | + * @param array $context Context to set/modify. |
|
41 | + * |
|
42 | + * @return array Updated context. |
|
43 | + */ |
|
44 | + protected function setContext(array $context) |
|
45 | + { |
|
46 | + return $context; |
|
47 | + } |
|
48 | 48 | } |
@@ -28,205 +28,205 @@ |
||
28 | 28 | abstract class AbstractMail implements MailInterface |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * Configuration Settings. |
|
33 | - * |
|
34 | - * @since 1.0.0 |
|
35 | - * |
|
36 | - * @var ConfigInterface |
|
37 | - */ |
|
38 | - protected $config; |
|
39 | - |
|
40 | - /** |
|
41 | - * Template that is used for the email. |
|
42 | - * |
|
43 | - * @since 1.0.0 |
|
44 | - * |
|
45 | - * @var TemplateInterface |
|
46 | - */ |
|
47 | - protected $template; |
|
48 | - |
|
49 | - /** |
|
50 | - * Content for the different sections. |
|
51 | - * |
|
52 | - * @since 1.0.0 |
|
53 | - * |
|
54 | - * @var array |
|
55 | - */ |
|
56 | - protected $sectionContent = []; |
|
57 | - |
|
58 | - /** |
|
59 | - * Format of the mail. |
|
60 | - * |
|
61 | - * @since 1.0.0 |
|
62 | - * |
|
63 | - * @var string |
|
64 | - */ |
|
65 | - protected $format; |
|
66 | - |
|
67 | - /** |
|
68 | - * Instantiate an AbstractMail object. |
|
69 | - * |
|
70 | - * @since 1.0.0 |
|
71 | - * |
|
72 | - * @param ConfigInterface $config |
|
73 | - */ |
|
74 | - public function __construct(ConfigInterface $config) |
|
75 | - { |
|
76 | - $this->config = $config; |
|
77 | - $this->setFormat(); |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Get the template to use for the renderer. |
|
82 | - * |
|
83 | - * @since 1.0.0 |
|
84 | - * |
|
85 | - * @return TemplateInterface Reference to the template that is used. |
|
86 | - * @throws RuntimeException |
|
87 | - */ |
|
88 | - public function getTemplate() |
|
89 | - { |
|
90 | - |
|
91 | - if (! $this->template) { |
|
92 | - $this->setDefaultTemplate(); |
|
93 | - } |
|
94 | - |
|
95 | - if (is_string($this->template)) { |
|
96 | - $this->template = $this->createTemplate($this->template); |
|
97 | - } |
|
98 | - |
|
99 | - return $this->template; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Set the template to use for the renderer. |
|
104 | - * |
|
105 | - * @since 1.0.0 |
|
106 | - * |
|
107 | - * @param string|TemplateInterface $template Template to use for the |
|
108 | - * renderer. |
|
109 | - * |
|
110 | - * @throws RuntimeException |
|
111 | - */ |
|
112 | - public function setTemplate($template) |
|
113 | - { |
|
114 | - if (is_string($template)) { |
|
115 | - $template = $this->createTemplate($template); |
|
116 | - } |
|
117 | - $this->template = $template; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Add a section to the Mail. |
|
122 | - * |
|
123 | - * @since 1.0.0 |
|
124 | - * |
|
125 | - * @param string $type Type of section to add. |
|
126 | - * @param string $content Content of the section. |
|
127 | - * |
|
128 | - * @throws RuntimeException |
|
129 | - */ |
|
130 | - public function addSection($type, $content) |
|
131 | - { |
|
132 | - $this->sectionContent[$type] = $content; |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Render the Mail for a given context. |
|
137 | - * |
|
138 | - * @since 1.0.0 |
|
139 | - * |
|
140 | - * @param array $context The context in which to render the email. |
|
141 | - * |
|
142 | - * @return string Rendered output of the email |
|
143 | - * @throws RuntimeException |
|
144 | - */ |
|
145 | - public function render(array $context) |
|
146 | - { |
|
147 | - |
|
148 | - $template = $this->getTemplate(); |
|
149 | - |
|
150 | - $context['template'] = $template; |
|
151 | - |
|
152 | - $sections = $template->getUsedSections(); |
|
153 | - |
|
154 | - $sectionFactory = new Factory($this->config, 'sections'); |
|
155 | - foreach ($sections as $section) { |
|
156 | - $content = null; |
|
157 | - if (array_key_exists($section, $this->sectionContent)) { |
|
158 | - $content = $this->sectionContent[$section]; |
|
159 | - } |
|
160 | - $context['sections'][$section] = $sectionFactory->create($section, |
|
161 | - [$section, $content]); |
|
162 | - } |
|
163 | - |
|
164 | - $context['format'] = $this->getFormat(); |
|
165 | - |
|
166 | - $context = $this->setContext($context); |
|
167 | - |
|
168 | - return $template->render($context); |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * Set the format of the mail. |
|
173 | - * |
|
174 | - * @since 1.0.0 |
|
175 | - * |
|
176 | - * @return string Format of the Mail. |
|
177 | - */ |
|
178 | - protected function getFormat() |
|
179 | - { |
|
180 | - return $this->format; |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * Set the format of the mail. |
|
185 | - * |
|
186 | - * @since 1.0.0 |
|
187 | - * |
|
188 | - * @return void |
|
189 | - */ |
|
190 | - abstract protected function setFormat(); |
|
191 | - |
|
192 | - /** |
|
193 | - * Set the template to the default template defined in the configuration. |
|
194 | - * |
|
195 | - * @since 1.0.0 |
|
196 | - * |
|
197 | - * @throws RuntimeException |
|
198 | - */ |
|
199 | - protected function setDefaultTemplate() |
|
200 | - { |
|
201 | - $defaultTemplate = $this->config->getKey('default_template'); |
|
202 | - $this->setTemplate($defaultTemplate); |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * Create an instance of a template. |
|
207 | - * |
|
208 | - * @since 1.0.0 |
|
209 | - * |
|
210 | - * @param string $template Template to instantiate. |
|
211 | - * |
|
212 | - * @return TemplateInterface $template Newly created instance. |
|
213 | - * @throws RuntimeException |
|
214 | - */ |
|
215 | - protected function createTemplate($template) |
|
216 | - { |
|
217 | - $templateFactory = new Factory($this->config, 'templates'); |
|
218 | - |
|
219 | - return $templateFactory->create($template, [$template]); |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Set the context of the mail. |
|
224 | - * |
|
225 | - * @since 1.0.0 |
|
226 | - * |
|
227 | - * @param array $context Context to set/modify. |
|
228 | - * |
|
229 | - * @return array Updated context. |
|
230 | - */ |
|
231 | - abstract protected function setContext(array $context); |
|
31 | + /** |
|
32 | + * Configuration Settings. |
|
33 | + * |
|
34 | + * @since 1.0.0 |
|
35 | + * |
|
36 | + * @var ConfigInterface |
|
37 | + */ |
|
38 | + protected $config; |
|
39 | + |
|
40 | + /** |
|
41 | + * Template that is used for the email. |
|
42 | + * |
|
43 | + * @since 1.0.0 |
|
44 | + * |
|
45 | + * @var TemplateInterface |
|
46 | + */ |
|
47 | + protected $template; |
|
48 | + |
|
49 | + /** |
|
50 | + * Content for the different sections. |
|
51 | + * |
|
52 | + * @since 1.0.0 |
|
53 | + * |
|
54 | + * @var array |
|
55 | + */ |
|
56 | + protected $sectionContent = []; |
|
57 | + |
|
58 | + /** |
|
59 | + * Format of the mail. |
|
60 | + * |
|
61 | + * @since 1.0.0 |
|
62 | + * |
|
63 | + * @var string |
|
64 | + */ |
|
65 | + protected $format; |
|
66 | + |
|
67 | + /** |
|
68 | + * Instantiate an AbstractMail object. |
|
69 | + * |
|
70 | + * @since 1.0.0 |
|
71 | + * |
|
72 | + * @param ConfigInterface $config |
|
73 | + */ |
|
74 | + public function __construct(ConfigInterface $config) |
|
75 | + { |
|
76 | + $this->config = $config; |
|
77 | + $this->setFormat(); |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Get the template to use for the renderer. |
|
82 | + * |
|
83 | + * @since 1.0.0 |
|
84 | + * |
|
85 | + * @return TemplateInterface Reference to the template that is used. |
|
86 | + * @throws RuntimeException |
|
87 | + */ |
|
88 | + public function getTemplate() |
|
89 | + { |
|
90 | + |
|
91 | + if (! $this->template) { |
|
92 | + $this->setDefaultTemplate(); |
|
93 | + } |
|
94 | + |
|
95 | + if (is_string($this->template)) { |
|
96 | + $this->template = $this->createTemplate($this->template); |
|
97 | + } |
|
98 | + |
|
99 | + return $this->template; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Set the template to use for the renderer. |
|
104 | + * |
|
105 | + * @since 1.0.0 |
|
106 | + * |
|
107 | + * @param string|TemplateInterface $template Template to use for the |
|
108 | + * renderer. |
|
109 | + * |
|
110 | + * @throws RuntimeException |
|
111 | + */ |
|
112 | + public function setTemplate($template) |
|
113 | + { |
|
114 | + if (is_string($template)) { |
|
115 | + $template = $this->createTemplate($template); |
|
116 | + } |
|
117 | + $this->template = $template; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Add a section to the Mail. |
|
122 | + * |
|
123 | + * @since 1.0.0 |
|
124 | + * |
|
125 | + * @param string $type Type of section to add. |
|
126 | + * @param string $content Content of the section. |
|
127 | + * |
|
128 | + * @throws RuntimeException |
|
129 | + */ |
|
130 | + public function addSection($type, $content) |
|
131 | + { |
|
132 | + $this->sectionContent[$type] = $content; |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Render the Mail for a given context. |
|
137 | + * |
|
138 | + * @since 1.0.0 |
|
139 | + * |
|
140 | + * @param array $context The context in which to render the email. |
|
141 | + * |
|
142 | + * @return string Rendered output of the email |
|
143 | + * @throws RuntimeException |
|
144 | + */ |
|
145 | + public function render(array $context) |
|
146 | + { |
|
147 | + |
|
148 | + $template = $this->getTemplate(); |
|
149 | + |
|
150 | + $context['template'] = $template; |
|
151 | + |
|
152 | + $sections = $template->getUsedSections(); |
|
153 | + |
|
154 | + $sectionFactory = new Factory($this->config, 'sections'); |
|
155 | + foreach ($sections as $section) { |
|
156 | + $content = null; |
|
157 | + if (array_key_exists($section, $this->sectionContent)) { |
|
158 | + $content = $this->sectionContent[$section]; |
|
159 | + } |
|
160 | + $context['sections'][$section] = $sectionFactory->create($section, |
|
161 | + [$section, $content]); |
|
162 | + } |
|
163 | + |
|
164 | + $context['format'] = $this->getFormat(); |
|
165 | + |
|
166 | + $context = $this->setContext($context); |
|
167 | + |
|
168 | + return $template->render($context); |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * Set the format of the mail. |
|
173 | + * |
|
174 | + * @since 1.0.0 |
|
175 | + * |
|
176 | + * @return string Format of the Mail. |
|
177 | + */ |
|
178 | + protected function getFormat() |
|
179 | + { |
|
180 | + return $this->format; |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * Set the format of the mail. |
|
185 | + * |
|
186 | + * @since 1.0.0 |
|
187 | + * |
|
188 | + * @return void |
|
189 | + */ |
|
190 | + abstract protected function setFormat(); |
|
191 | + |
|
192 | + /** |
|
193 | + * Set the template to the default template defined in the configuration. |
|
194 | + * |
|
195 | + * @since 1.0.0 |
|
196 | + * |
|
197 | + * @throws RuntimeException |
|
198 | + */ |
|
199 | + protected function setDefaultTemplate() |
|
200 | + { |
|
201 | + $defaultTemplate = $this->config->getKey('default_template'); |
|
202 | + $this->setTemplate($defaultTemplate); |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * Create an instance of a template. |
|
207 | + * |
|
208 | + * @since 1.0.0 |
|
209 | + * |
|
210 | + * @param string $template Template to instantiate. |
|
211 | + * |
|
212 | + * @return TemplateInterface $template Newly created instance. |
|
213 | + * @throws RuntimeException |
|
214 | + */ |
|
215 | + protected function createTemplate($template) |
|
216 | + { |
|
217 | + $templateFactory = new Factory($this->config, 'templates'); |
|
218 | + |
|
219 | + return $templateFactory->create($template, [$template]); |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Set the context of the mail. |
|
224 | + * |
|
225 | + * @since 1.0.0 |
|
226 | + * |
|
227 | + * @param array $context Context to set/modify. |
|
228 | + * |
|
229 | + * @return array Updated context. |
|
230 | + */ |
|
231 | + abstract protected function setContext(array $context); |
|
232 | 232 | } |
@@ -88,7 +88,7 @@ |
||
88 | 88 | public function getTemplate() |
89 | 89 | { |
90 | 90 | |
91 | - if (! $this->template) { |
|
91 | + if ( ! $this->template) { |
|
92 | 92 | $this->setDefaultTemplate(); |
93 | 93 | } |
94 | 94 |
@@ -22,27 +22,27 @@ |
||
22 | 22 | class TextMail extends AbstractMail |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Set the format of the mail. |
|
27 | - * |
|
28 | - * @since 1.0.0 |
|
29 | - */ |
|
30 | - protected function setFormat() |
|
31 | - { |
|
32 | - $this->format = 'text'; |
|
33 | - } |
|
25 | + /** |
|
26 | + * Set the format of the mail. |
|
27 | + * |
|
28 | + * @since 1.0.0 |
|
29 | + */ |
|
30 | + protected function setFormat() |
|
31 | + { |
|
32 | + $this->format = 'text'; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Set the context of the renderer. |
|
37 | - * |
|
38 | - * @since 1.0.0 |
|
39 | - * |
|
40 | - * @param array $context Context to set/modify. |
|
41 | - * |
|
42 | - * @return array Updated context. |
|
43 | - */ |
|
44 | - protected function setContext(array $context) |
|
45 | - { |
|
46 | - return $context; |
|
47 | - } |
|
35 | + /** |
|
36 | + * Set the context of the renderer. |
|
37 | + * |
|
38 | + * @since 1.0.0 |
|
39 | + * |
|
40 | + * @param array $context Context to set/modify. |
|
41 | + * |
|
42 | + * @return array Updated context. |
|
43 | + */ |
|
44 | + protected function setContext(array $context) |
|
45 | + { |
|
46 | + return $context; |
|
47 | + } |
|
48 | 48 | } |
@@ -24,36 +24,36 @@ |
||
24 | 24 | interface MailInterface extends Renderable |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * Set the template that the email will use. |
|
29 | - * |
|
30 | - * @since 1.0.0 |
|
31 | - * |
|
32 | - * @param string|TemplateInterface $template Template to use. |
|
33 | - * |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public function setTemplate($template); |
|
27 | + /** |
|
28 | + * Set the template that the email will use. |
|
29 | + * |
|
30 | + * @since 1.0.0 |
|
31 | + * |
|
32 | + * @param string|TemplateInterface $template Template to use. |
|
33 | + * |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public function setTemplate($template); |
|
37 | 37 | |
38 | - /** |
|
39 | - * Get the instance of the template. |
|
40 | - * |
|
41 | - * @since 1.0.0 |
|
42 | - * |
|
43 | - * @return TemplateInterface |
|
44 | - */ |
|
45 | - public function getTemplate(); |
|
38 | + /** |
|
39 | + * Get the instance of the template. |
|
40 | + * |
|
41 | + * @since 1.0.0 |
|
42 | + * |
|
43 | + * @return TemplateInterface |
|
44 | + */ |
|
45 | + public function getTemplate(); |
|
46 | 46 | |
47 | - /** |
|
48 | - * Add a section to the Mail. |
|
49 | - * |
|
50 | - * @since 1.0.0 |
|
51 | - * |
|
52 | - * @param string $type Type of section to add. |
|
53 | - * @param string $content Content of the section. |
|
54 | - * |
|
55 | - * @return void |
|
56 | - * @throws RuntimeException |
|
57 | - */ |
|
58 | - public function addSection($type, $content); |
|
47 | + /** |
|
48 | + * Add a section to the Mail. |
|
49 | + * |
|
50 | + * @since 1.0.0 |
|
51 | + * |
|
52 | + * @param string $type Type of section to add. |
|
53 | + * @param string $content Content of the section. |
|
54 | + * |
|
55 | + * @return void |
|
56 | + * @throws RuntimeException |
|
57 | + */ |
|
58 | + public function addSection($type, $content); |
|
59 | 59 | } |
@@ -22,15 +22,15 @@ |
||
22 | 22 | interface ValidatorInterface |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Validate the content for a given context. |
|
27 | - * |
|
28 | - * @since 1.0.0 |
|
29 | - * |
|
30 | - * @param string $content Content to validate. |
|
31 | - * @param array $context Context in which to validate. |
|
32 | - * |
|
33 | - * @return string Validated content. |
|
34 | - */ |
|
35 | - public function validate($content, array $context); |
|
25 | + /** |
|
26 | + * Validate the content for a given context. |
|
27 | + * |
|
28 | + * @since 1.0.0 |
|
29 | + * |
|
30 | + * @param string $content Content to validate. |
|
31 | + * @param array $context Context in which to validate. |
|
32 | + * |
|
33 | + * @return string Validated content. |
|
34 | + */ |
|
35 | + public function validate($content, array $context); |
|
36 | 36 | } |