Passed
Push — master ( 4633d8...be0c82 )
by Alain
02:10
created
src/Mail/AbstractMail.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,6 @@
 block discarded – undo
19 19
 use BrightNucleus\ChainMail\Template;
20 20
 use BrightNucleus\Config\ConfigInterface;
21 21
 use BrightNucleus\Config\Exception\FailedToProcessConfigException;
22
-use BrightNucleus\View;
23 22
 use BrightNucleus\View\Location\FilesystemLocation;
24 23
 use BrightNucleus\View\ViewBuilder;
25 24
 use Exception;
Please login to merge, or discard this patch.
Indentation   +300 added lines, -300 removed lines patch added patch discarded remove patch
@@ -36,304 +36,304 @@
 block discarded – undo
36 36
 abstract class AbstractMail implements Mail
37 37
 {
38 38
 
39
-    /**
40
-     * Configuration Settings.
41
-     *
42
-     * @since 1.0.0
43
-     *
44
-     * @var ConfigInterface
45
-     */
46
-    protected $config;
47
-
48
-    /**
49
-     * Template that is used for the email.
50
-     *
51
-     * @since 1.0.0
52
-     *
53
-     * @var Template
54
-     */
55
-    protected $template;
56
-
57
-    /**
58
-     * Content for the different sections.
59
-     *
60
-     * @since 1.0.0
61
-     *
62
-     * @var array
63
-     */
64
-    protected $sectionContent = [];
65
-
66
-    /**
67
-     * Format of the mail.
68
-     *
69
-     * @since 1.0.0
70
-     *
71
-     * @var string
72
-     */
73
-    protected $format;
74
-
75
-    /**
76
-     * ViewBuilder to create template and section views.
77
-     *
78
-     * @since 1.0.0
79
-     *
80
-     * @var ViewBuilder
81
-     */
82
-    protected $viewBuilder;
83
-
84
-    /**
85
-     * Instantiate an AbstractMail object.
86
-     *
87
-     * @since 1.0.0
88
-     *
89
-     * @param ConfigInterface $config The Config to use.
90
-     *
91
-     * @throws FailedToProcessConfigException If the Config could not be processed.
92
-     */
93
-    public function __construct(ConfigInterface $config)
94
-    {
95
-        $this->config = $config;
96
-        $this->setFormat();
97
-
98
-        $this->viewBuilder = new ViewBuilder($config
99
-            ? $config->getSubConfig('ViewBuilder')
100
-            : null
101
-        );
102
-
103
-        foreach ($this->config->getKey('view_root_locations') as $folder) {
104
-            $this->viewBuilder->addLocation(
105
-                new FilesystemLocation($folder)
106
-            );
107
-        }
108
-    }
109
-
110
-    /**
111
-     * Get the template to use for the renderer.
112
-     *
113
-     * @since 1.0.0
114
-     *
115
-     * @return Template Reference to the template that is used.
116
-     * @throws RuntimeException
117
-     */
118
-    public function getTemplate()
119
-    {
120
-
121
-        if ( ! $this->template) {
122
-            $this->setDefaultTemplate();
123
-        }
124
-
125
-        if (is_string($this->template)) {
126
-            $this->template = $this->createTemplate($this->template);
127
-        }
128
-
129
-        return $this->template;
130
-    }
131
-
132
-    /**
133
-     * Set the template to use for the renderer.
134
-     *
135
-     * @since 1.0.0
136
-     *
137
-     * @param string|Template $template          Template to use for the
138
-     *                                           renderer.
139
-     *
140
-     * @return Mail
141
-     * @throws InvalidTemplate If the template class could not be instantiated.
142
-     * @throws InvalidTemplate If the template type is not recognized.
143
-     */
144
-    public function setTemplate($template)
145
-    {
146
-        try {
147
-            if (is_string($template)) {
148
-                $template = $this->createTemplate($template);
149
-            }
150
-        } catch (Exception $exception) {
151
-            throw new InvalidTemplate(
152
-                'Could not instantiate the template class "%1$s". Reason: "%2$s".',
153
-                $template,
154
-                $exception->getMessage()
155
-            );
156
-        }
157
-
158
-        if ( ! $template instanceof Template) {
159
-            throw new InvalidTemplate(
160
-                'Could not set the template, invalid type.',
161
-                (array)$template
162
-            );
163
-        }
164
-        $this->template = $template;
165
-
166
-        return $this;
167
-    }
168
-
169
-    /**
170
-     * Add a section to the Mail.
171
-     *
172
-     * @since 1.0.0
173
-     *
174
-     * @param string $type    Type of section to add.
175
-     * @param string $content Content of the section.
176
-     *
177
-     * @throws RuntimeException
178
-     */
179
-    public function addSection($type, $content)
180
-    {
181
-        $this->sectionContent[$type] = $content;
182
-    }
183
-
184
-    /**
185
-     * Render the Mail for a given context.
186
-     *
187
-     * @since 1.0.0
188
-     *
189
-     * @param array $context The context in which to render the email.
190
-     *
191
-     * @return string Rendered output of the email
192
-     */
193
-    public function render(array $context)
194
-    {
195
-        $template = $this->getTemplate();
196
-
197
-        $context['template'] = $template;
198
-
199
-        $this->instantiateSections($template->getUsedSections(), $context);
200
-
201
-        $context['format'] = $this->getFormat();
202
-
203
-        $context = $this->setContext($context);
204
-
205
-        return $template->render($context);
206
-    }
207
-
208
-    /**
209
-     * Send the email to one or more recipients.
210
-     *
211
-     * @since 1.0.0
212
-     *
213
-     * @param Recipients|EmailAddress|array|string $recipients
214
-     *
215
-     * @return Mail
216
-     */
217
-    public function sendTo($recipients)
218
-    {
219
-        if ($recipients instanceof EmailAddress) {
220
-            return $this->executeSend($recipients);
221
-        }
222
-
223
-        if (is_string($recipients)) {
224
-            return $this->sendTo(new EmailAddress($recipients));
225
-        }
226
-
227
-        if ($recipients instanceof Recipients) {
228
-            array_walk($recipients, [$this, 'sendTo']);
229
-
230
-            return $this;
231
-        }
232
-    }
233
-
234
-    /**
235
-     * Execute the sending of one individual email.
236
-     *
237
-     * @since 1.0.0
238
-     *
239
-     * @param EmailAddress $recipient Recipient to send the email to.
240
-     *
241
-     * @return Mail
242
-     */
243
-    protected function executeSend(EmailAddress $recipient)
244
-    {
245
-        // Do the actual sending.
246
-        echo "Sending email to ${recipient}...";
247
-
248
-        return $this;
249
-    }
250
-
251
-    /**
252
-     * Instantiate the requested sections for a template.
253
-     *
254
-     * @since 1.0.0
255
-     *
256
-     * @param array $sections Sections to instantiate.
257
-     * @param array $context  The context in which to instantiate the sections.
258
-     */
259
-    protected function instantiateSections(array $sections, array &$context)
260
-    {
261
-        $sectionFactory = new Factory($this->config, 'sections');
262
-
263
-        foreach ($sections as $section) {
264
-
265
-            $content = null;
266
-
267
-            if (array_key_exists($section, $this->sectionContent)) {
268
-                $content = $this->sectionContent[$section];
269
-            }
270
-
271
-            $context['sections'][$section] = $sectionFactory->create(
272
-                $section,
273
-                [$section, $content, $this->viewBuilder]
274
-            );
275
-        }
276
-    }
277
-
278
-    /**
279
-     * Set the format of the mail.
280
-     *
281
-     * @since 1.0.0
282
-     *
283
-     * @return string Format of the Mail.
284
-     */
285
-    protected function getFormat()
286
-    {
287
-        return $this->format;
288
-    }
289
-
290
-    /**
291
-     * Set the format of the mail.
292
-     *
293
-     * @since 1.0.0
294
-     *
295
-     * @return void
296
-     */
297
-    abstract protected function setFormat();
298
-
299
-    /**
300
-     * Set the template to the default template defined in the configuration.
301
-     *
302
-     * @since 1.0.0
303
-     *
304
-     * @throws RuntimeException
305
-     */
306
-    protected function setDefaultTemplate()
307
-    {
308
-        $defaultTemplate = $this->config->getKey('default_template');
309
-        $this->setTemplate($defaultTemplate);
310
-    }
311
-
312
-    /**
313
-     * Create an instance of a template.
314
-     *
315
-     * @since 1.0.0
316
-     *
317
-     * @param string $template Template to instantiate.
318
-     *
319
-     * @return Template $template Newly created instance.
320
-     * @throws RuntimeException
321
-     */
322
-    protected function createTemplate($template)
323
-    {
324
-        $templateFactory = new Factory($this->config, 'templates');
325
-
326
-        return $templateFactory->create($template, [$template, $this->viewBuilder]);
327
-    }
328
-
329
-    /**
330
-     * Set the context of the mail.
331
-     *
332
-     * @since 1.0.0
333
-     *
334
-     * @param array $context Context to set/modify.
335
-     *
336
-     * @return array Updated context.
337
-     */
338
-    abstract protected function setContext(array $context);
39
+	/**
40
+	 * Configuration Settings.
41
+	 *
42
+	 * @since 1.0.0
43
+	 *
44
+	 * @var ConfigInterface
45
+	 */
46
+	protected $config;
47
+
48
+	/**
49
+	 * Template that is used for the email.
50
+	 *
51
+	 * @since 1.0.0
52
+	 *
53
+	 * @var Template
54
+	 */
55
+	protected $template;
56
+
57
+	/**
58
+	 * Content for the different sections.
59
+	 *
60
+	 * @since 1.0.0
61
+	 *
62
+	 * @var array
63
+	 */
64
+	protected $sectionContent = [];
65
+
66
+	/**
67
+	 * Format of the mail.
68
+	 *
69
+	 * @since 1.0.0
70
+	 *
71
+	 * @var string
72
+	 */
73
+	protected $format;
74
+
75
+	/**
76
+	 * ViewBuilder to create template and section views.
77
+	 *
78
+	 * @since 1.0.0
79
+	 *
80
+	 * @var ViewBuilder
81
+	 */
82
+	protected $viewBuilder;
83
+
84
+	/**
85
+	 * Instantiate an AbstractMail object.
86
+	 *
87
+	 * @since 1.0.0
88
+	 *
89
+	 * @param ConfigInterface $config The Config to use.
90
+	 *
91
+	 * @throws FailedToProcessConfigException If the Config could not be processed.
92
+	 */
93
+	public function __construct(ConfigInterface $config)
94
+	{
95
+		$this->config = $config;
96
+		$this->setFormat();
97
+
98
+		$this->viewBuilder = new ViewBuilder($config
99
+			? $config->getSubConfig('ViewBuilder')
100
+			: null
101
+		);
102
+
103
+		foreach ($this->config->getKey('view_root_locations') as $folder) {
104
+			$this->viewBuilder->addLocation(
105
+				new FilesystemLocation($folder)
106
+			);
107
+		}
108
+	}
109
+
110
+	/**
111
+	 * Get the template to use for the renderer.
112
+	 *
113
+	 * @since 1.0.0
114
+	 *
115
+	 * @return Template Reference to the template that is used.
116
+	 * @throws RuntimeException
117
+	 */
118
+	public function getTemplate()
119
+	{
120
+
121
+		if ( ! $this->template) {
122
+			$this->setDefaultTemplate();
123
+		}
124
+
125
+		if (is_string($this->template)) {
126
+			$this->template = $this->createTemplate($this->template);
127
+		}
128
+
129
+		return $this->template;
130
+	}
131
+
132
+	/**
133
+	 * Set the template to use for the renderer.
134
+	 *
135
+	 * @since 1.0.0
136
+	 *
137
+	 * @param string|Template $template          Template to use for the
138
+	 *                                           renderer.
139
+	 *
140
+	 * @return Mail
141
+	 * @throws InvalidTemplate If the template class could not be instantiated.
142
+	 * @throws InvalidTemplate If the template type is not recognized.
143
+	 */
144
+	public function setTemplate($template)
145
+	{
146
+		try {
147
+			if (is_string($template)) {
148
+				$template = $this->createTemplate($template);
149
+			}
150
+		} catch (Exception $exception) {
151
+			throw new InvalidTemplate(
152
+				'Could not instantiate the template class "%1$s". Reason: "%2$s".',
153
+				$template,
154
+				$exception->getMessage()
155
+			);
156
+		}
157
+
158
+		if ( ! $template instanceof Template) {
159
+			throw new InvalidTemplate(
160
+				'Could not set the template, invalid type.',
161
+				(array)$template
162
+			);
163
+		}
164
+		$this->template = $template;
165
+
166
+		return $this;
167
+	}
168
+
169
+	/**
170
+	 * Add a section to the Mail.
171
+	 *
172
+	 * @since 1.0.0
173
+	 *
174
+	 * @param string $type    Type of section to add.
175
+	 * @param string $content Content of the section.
176
+	 *
177
+	 * @throws RuntimeException
178
+	 */
179
+	public function addSection($type, $content)
180
+	{
181
+		$this->sectionContent[$type] = $content;
182
+	}
183
+
184
+	/**
185
+	 * Render the Mail for a given context.
186
+	 *
187
+	 * @since 1.0.0
188
+	 *
189
+	 * @param array $context The context in which to render the email.
190
+	 *
191
+	 * @return string Rendered output of the email
192
+	 */
193
+	public function render(array $context)
194
+	{
195
+		$template = $this->getTemplate();
196
+
197
+		$context['template'] = $template;
198
+
199
+		$this->instantiateSections($template->getUsedSections(), $context);
200
+
201
+		$context['format'] = $this->getFormat();
202
+
203
+		$context = $this->setContext($context);
204
+
205
+		return $template->render($context);
206
+	}
207
+
208
+	/**
209
+	 * Send the email to one or more recipients.
210
+	 *
211
+	 * @since 1.0.0
212
+	 *
213
+	 * @param Recipients|EmailAddress|array|string $recipients
214
+	 *
215
+	 * @return Mail
216
+	 */
217
+	public function sendTo($recipients)
218
+	{
219
+		if ($recipients instanceof EmailAddress) {
220
+			return $this->executeSend($recipients);
221
+		}
222
+
223
+		if (is_string($recipients)) {
224
+			return $this->sendTo(new EmailAddress($recipients));
225
+		}
226
+
227
+		if ($recipients instanceof Recipients) {
228
+			array_walk($recipients, [$this, 'sendTo']);
229
+
230
+			return $this;
231
+		}
232
+	}
233
+
234
+	/**
235
+	 * Execute the sending of one individual email.
236
+	 *
237
+	 * @since 1.0.0
238
+	 *
239
+	 * @param EmailAddress $recipient Recipient to send the email to.
240
+	 *
241
+	 * @return Mail
242
+	 */
243
+	protected function executeSend(EmailAddress $recipient)
244
+	{
245
+		// Do the actual sending.
246
+		echo "Sending email to ${recipient}...";
247
+
248
+		return $this;
249
+	}
250
+
251
+	/**
252
+	 * Instantiate the requested sections for a template.
253
+	 *
254
+	 * @since 1.0.0
255
+	 *
256
+	 * @param array $sections Sections to instantiate.
257
+	 * @param array $context  The context in which to instantiate the sections.
258
+	 */
259
+	protected function instantiateSections(array $sections, array &$context)
260
+	{
261
+		$sectionFactory = new Factory($this->config, 'sections');
262
+
263
+		foreach ($sections as $section) {
264
+
265
+			$content = null;
266
+
267
+			if (array_key_exists($section, $this->sectionContent)) {
268
+				$content = $this->sectionContent[$section];
269
+			}
270
+
271
+			$context['sections'][$section] = $sectionFactory->create(
272
+				$section,
273
+				[$section, $content, $this->viewBuilder]
274
+			);
275
+		}
276
+	}
277
+
278
+	/**
279
+	 * Set the format of the mail.
280
+	 *
281
+	 * @since 1.0.0
282
+	 *
283
+	 * @return string Format of the Mail.
284
+	 */
285
+	protected function getFormat()
286
+	{
287
+		return $this->format;
288
+	}
289
+
290
+	/**
291
+	 * Set the format of the mail.
292
+	 *
293
+	 * @since 1.0.0
294
+	 *
295
+	 * @return void
296
+	 */
297
+	abstract protected function setFormat();
298
+
299
+	/**
300
+	 * Set the template to the default template defined in the configuration.
301
+	 *
302
+	 * @since 1.0.0
303
+	 *
304
+	 * @throws RuntimeException
305
+	 */
306
+	protected function setDefaultTemplate()
307
+	{
308
+		$defaultTemplate = $this->config->getKey('default_template');
309
+		$this->setTemplate($defaultTemplate);
310
+	}
311
+
312
+	/**
313
+	 * Create an instance of a template.
314
+	 *
315
+	 * @since 1.0.0
316
+	 *
317
+	 * @param string $template Template to instantiate.
318
+	 *
319
+	 * @return Template $template Newly created instance.
320
+	 * @throws RuntimeException
321
+	 */
322
+	protected function createTemplate($template)
323
+	{
324
+		$templateFactory = new Factory($this->config, 'templates');
325
+
326
+		return $templateFactory->create($template, [$template, $this->viewBuilder]);
327
+	}
328
+
329
+	/**
330
+	 * Set the context of the mail.
331
+	 *
332
+	 * @since 1.0.0
333
+	 *
334
+	 * @param array $context Context to set/modify.
335
+	 *
336
+	 * @return array Updated context.
337
+	 */
338
+	abstract protected function setContext(array $context);
339 339
 }
Please login to merge, or discard this patch.
src/Support/Domain.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
     /**
35 35
      * Instantiate a Domain object.
36 36
      *
37
-     * @param Domain|string $domain
37
+     * @param string $domain
38 38
      *
39 39
      * @throws InvalidDomain If the domain is not valid.
40 40
      */
Please login to merge, or discard this patch.
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -24,57 +24,57 @@
 block discarded – undo
24 24
 class Domain
25 25
 {
26 26
 
27
-    /**
28
-     * Domain name.
29
-     *
30
-     * @var string
31
-     */
32
-    protected $domain;
27
+	/**
28
+	 * Domain name.
29
+	 *
30
+	 * @var string
31
+	 */
32
+	protected $domain;
33 33
 
34
-    /**
35
-     * Instantiate a Domain object.
36
-     *
37
-     * @param Domain|string $domain
38
-     *
39
-     * @throws InvalidDomain If the domain is not valid.
40
-     */
41
-    public function __construct($domain)
42
-    {
43
-        if ( ! $this->isValid($domain)) {
44
-            throw InvalidDomain::from($domain);
45
-        }
34
+	/**
35
+	 * Instantiate a Domain object.
36
+	 *
37
+	 * @param Domain|string $domain
38
+	 *
39
+	 * @throws InvalidDomain If the domain is not valid.
40
+	 */
41
+	public function __construct($domain)
42
+	{
43
+		if ( ! $this->isValid($domain)) {
44
+			throw InvalidDomain::from($domain);
45
+		}
46 46
 
47
-        $this->domain = (string)$domain;
48
-    }
47
+		$this->domain = (string)$domain;
48
+	}
49 49
 
50
-    /**
51
-     * Return the domain name.
52
-     *
53
-     * @return string
54
-     */
55
-    public function getDomain()
56
-    {
57
-        return $this->domain;
58
-    }
50
+	/**
51
+	 * Return the domain name.
52
+	 *
53
+	 * @return string
54
+	 */
55
+	public function getDomain()
56
+	{
57
+		return $this->domain;
58
+	}
59 59
 
60
-    /**
61
-     * Reutrn a string representation of the Domain object.
62
-     *
63
-     * @return string
64
-     */
65
-    public function __toString()
66
-    {
67
-        return $this->getDomain();
68
-    }
60
+	/**
61
+	 * Reutrn a string representation of the Domain object.
62
+	 *
63
+	 * @return string
64
+	 */
65
+	public function __toString()
66
+	{
67
+		return $this->getDomain();
68
+	}
69 69
 
70
-    /**
71
-     * @param $domain
72
-     *
73
-     * @return bool
74
-     */
75
-    protected function isValid($domain)
76
-    {
77
-        // TODO: Implement real validation.
78
-        return $domain === trim($domain);
79
-    }
70
+	/**
71
+	 * @param $domain
72
+	 *
73
+	 * @return bool
74
+	 */
75
+	protected function isValid($domain)
76
+	{
77
+		// TODO: Implement real validation.
78
+		return $domain === trim($domain);
79
+	}
80 80
 }
81 81
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@
 block discarded – undo
44 44
             throw InvalidDomain::from($domain);
45 45
         }
46 46
 
47
-        $this->domain = (string)$domain;
47
+        $this->domain = (string) $domain;
48 48
     }
49 49
 
50 50
     /**
Please login to merge, or discard this patch.
src/ChainMail.php 1 patch
Indentation   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -26,114 +26,114 @@
 block discarded – undo
26 26
 class ChainMail
27 27
 {
28 28
 
29
-    const DEFAULT_CONFIG = __DIR__ . '/../config/defaults.php';
30
-
31
-    /**
32
-     * Configuration Settings.
33
-     *
34
-     * @since 1.0.0
35
-     *
36
-     * @var ConfigInterface
37
-     */
38
-    protected $config;
39
-
40
-    /**
41
-     * Instantiate a ChainMail object.
42
-     *
43
-     * @since 1.0.0
44
-     *
45
-     * @param ConfigInterface|null $config Optional. Configuration settings.
46
-     */
47
-    public function __construct(ConfigInterface $config = null)
48
-    {
49
-
50
-        $defaults = ConfigFactory::create(include(self::DEFAULT_CONFIG));
51
-
52
-        if ( ! $config) {
53
-            $this->config = $defaults;
54
-
55
-            return;
56
-        }
57
-
58
-        $this->config = ConfigFactory::create(array_replace_recursive(
59
-                (array)$defaults,
60
-                (array)$config)
61
-        );
62
-    }
63
-
64
-    /**
65
-     * Render a specific section.
66
-     *
67
-     * @since 1.0.0
68
-     *
69
-     * @param string $sectionType Type of section to render.
70
-     * @param array  $context     The context in which to render the section.
71
-     *
72
-     * @return string Rendered HTML.
73
-     */
74
-    public static function renderSection($sectionType, array $context)
75
-    {
76
-        /** @var Section $section */
77
-        $section = $context['sections'][$sectionType];
78
-
79
-        return $section->render($context);
80
-    }
81
-
82
-    /**
83
-     * Get an array of strings representing the sections that are used by the
84
-     * template.
85
-     *
86
-     * @since 1.0.0
87
-     *
88
-     * @param array $context The context in which to render the section.
89
-     *
90
-     * @return array Array of strings with section types.
91
-     */
92
-    public static function getUsedSections(array $context)
93
-    {
94
-        /** @var Template $template */
95
-        $template = $context['template'];
96
-
97
-        return $template->getUsedSections();
98
-    }
99
-
100
-    /**
101
-     * Render all used sections.
102
-     *
103
-     * @since 1.0.0
104
-     *
105
-     * @param array $context The context in which to render the section.
106
-     *
107
-     * @return string Rendered HTML.
108
-     */
109
-    public static function renderSections(array $context)
110
-    {
111
-        $output = '';
112
-
113
-        foreach (self::getUsedSections($context) as $section) {
114
-            $output .= self::renderSection($section, $context);
115
-        }
116
-
117
-        return $output;
118
-    }
119
-
120
-    /**
121
-     * Create a new mail object.
122
-     *
123
-     * @since 1.0.0
124
-     *
125
-     * @param string          $format   Optional. Format to use.
126
-     * @param string|Template $template Optional. Template to be used.
127
-     *
128
-     * @return Mail
129
-     */
130
-    public function createMail($format = 'html', $template = 'BasicTemplate')
131
-    {
132
-        $mail_factory = new Factory($this->config, 'mails');
133
-        $mail_class   = $this->config->getKey('formats')[$format]['mail'];
134
-        $mail         = $mail_factory->create($mail_class);
135
-        $mail->setTemplate($template);
136
-
137
-        return $mail;
138
-    }
29
+	const DEFAULT_CONFIG = __DIR__ . '/../config/defaults.php';
30
+
31
+	/**
32
+	 * Configuration Settings.
33
+	 *
34
+	 * @since 1.0.0
35
+	 *
36
+	 * @var ConfigInterface
37
+	 */
38
+	protected $config;
39
+
40
+	/**
41
+	 * Instantiate a ChainMail object.
42
+	 *
43
+	 * @since 1.0.0
44
+	 *
45
+	 * @param ConfigInterface|null $config Optional. Configuration settings.
46
+	 */
47
+	public function __construct(ConfigInterface $config = null)
48
+	{
49
+
50
+		$defaults = ConfigFactory::create(include(self::DEFAULT_CONFIG));
51
+
52
+		if ( ! $config) {
53
+			$this->config = $defaults;
54
+
55
+			return;
56
+		}
57
+
58
+		$this->config = ConfigFactory::create(array_replace_recursive(
59
+				(array)$defaults,
60
+				(array)$config)
61
+		);
62
+	}
63
+
64
+	/**
65
+	 * Render a specific section.
66
+	 *
67
+	 * @since 1.0.0
68
+	 *
69
+	 * @param string $sectionType Type of section to render.
70
+	 * @param array  $context     The context in which to render the section.
71
+	 *
72
+	 * @return string Rendered HTML.
73
+	 */
74
+	public static function renderSection($sectionType, array $context)
75
+	{
76
+		/** @var Section $section */
77
+		$section = $context['sections'][$sectionType];
78
+
79
+		return $section->render($context);
80
+	}
81
+
82
+	/**
83
+	 * Get an array of strings representing the sections that are used by the
84
+	 * template.
85
+	 *
86
+	 * @since 1.0.0
87
+	 *
88
+	 * @param array $context The context in which to render the section.
89
+	 *
90
+	 * @return array Array of strings with section types.
91
+	 */
92
+	public static function getUsedSections(array $context)
93
+	{
94
+		/** @var Template $template */
95
+		$template = $context['template'];
96
+
97
+		return $template->getUsedSections();
98
+	}
99
+
100
+	/**
101
+	 * Render all used sections.
102
+	 *
103
+	 * @since 1.0.0
104
+	 *
105
+	 * @param array $context The context in which to render the section.
106
+	 *
107
+	 * @return string Rendered HTML.
108
+	 */
109
+	public static function renderSections(array $context)
110
+	{
111
+		$output = '';
112
+
113
+		foreach (self::getUsedSections($context) as $section) {
114
+			$output .= self::renderSection($section, $context);
115
+		}
116
+
117
+		return $output;
118
+	}
119
+
120
+	/**
121
+	 * Create a new mail object.
122
+	 *
123
+	 * @since 1.0.0
124
+	 *
125
+	 * @param string          $format   Optional. Format to use.
126
+	 * @param string|Template $template Optional. Template to be used.
127
+	 *
128
+	 * @return Mail
129
+	 */
130
+	public function createMail($format = 'html', $template = 'BasicTemplate')
131
+	{
132
+		$mail_factory = new Factory($this->config, 'mails');
133
+		$mail_class   = $this->config->getKey('formats')[$format]['mail'];
134
+		$mail         = $mail_factory->create($mail_class);
135
+		$mail->setTemplate($template);
136
+
137
+		return $mail;
138
+	}
139 139
 }
Please login to merge, or discard this patch.
src/Exception/InvalidEmailAddress.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -24,15 +24,15 @@
 block discarded – undo
24 24
 class InvalidEmailAddress extends RuntimeException implements ChainmailException
25 25
 {
26 26
 
27
-    /**
28
-     * Create an InvalidEmailAddress exception based on a specific email.
29
-     *
30
-     * @param string $email Email that failed validation.
31
-     *
32
-     * @return static
33
-     */
34
-    public static function from($email)
35
-    {
36
-        return new static(sprintf('Invalid email address: "%1$s".', $email));
37
-    }
27
+	/**
28
+	 * Create an InvalidEmailAddress exception based on a specific email.
29
+	 *
30
+	 * @param string $email Email that failed validation.
31
+	 *
32
+	 * @return static
33
+	 */
34
+	public static function from($email)
35
+	{
36
+		return new static(sprintf('Invalid email address: "%1$s".', $email));
37
+	}
38 38
 }
Please login to merge, or discard this patch.
src/Exception/InvalidDomain.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -24,15 +24,15 @@
 block discarded – undo
24 24
 class InvalidDomain extends RuntimeException implements ChainmailException
25 25
 {
26 26
 
27
-    /**
28
-     * Create an InvalidDomain exception based on a specific domain.
29
-     *
30
-     * @param string $domain Email that failed validation.
31
-     *
32
-     * @return static
33
-     */
34
-    public static function from($domain)
35
-    {
36
-        return new static(sprintf('Invalid domain name: "%1$s".', $domain));
37
-    }
27
+	/**
28
+	 * Create an InvalidDomain exception based on a specific domain.
29
+	 *
30
+	 * @param string $domain Email that failed validation.
31
+	 *
32
+	 * @return static
33
+	 */
34
+	public static function from($domain)
35
+	{
36
+		return new static(sprintf('Invalid domain name: "%1$s".', $domain));
37
+	}
38 38
 }
Please login to merge, or discard this patch.
src/Recipients.php 2 patches
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -25,30 +25,30 @@
 block discarded – undo
25 25
 class Recipients extends ArrayCollection
26 26
 {
27 27
 
28
-    public function __construct(array $emails)
29
-    {
30
-        parent::__construct(array_filter(
31
-            array_map(function ($value) {
32
-                if ($value instanceof EmailAddress) {
33
-                    return $value;
34
-                }
28
+	public function __construct(array $emails)
29
+	{
30
+		parent::__construct(array_filter(
31
+			array_map(function ($value) {
32
+				if ($value instanceof EmailAddress) {
33
+					return $value;
34
+				}
35 35
 
36
-                return new EmailAddress($value);
37
-            }, $emails)
38
-        ));
39
-    }
36
+				return new EmailAddress($value);
37
+			}, $emails)
38
+		));
39
+	}
40 40
 
41
-    /**
42
-     * Add an email address to the Recipients collection.
43
-     *
44
-     * @param mixed $email Email address to add.
45
-     *
46
-     * @return static
47
-     */
48
-    public function add($email)
49
-    {
50
-        parent::add(new EmailAddress($email));
41
+	/**
42
+	 * Add an email address to the Recipients collection.
43
+	 *
44
+	 * @param mixed $email Email address to add.
45
+	 *
46
+	 * @return static
47
+	 */
48
+	public function add($email)
49
+	{
50
+		parent::add(new EmailAddress($email));
51 51
 
52
-        return $this;
53
-    }
52
+		return $this;
53
+	}
54 54
 }
55 55
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@
 block discarded – undo
28 28
     public function __construct(array $emails)
29 29
     {
30 30
         parent::__construct(array_filter(
31
-            array_map(function ($value) {
31
+            array_map(function($value) {
32 32
                 if ($value instanceof EmailAddress) {
33 33
                     return $value;
34 34
                 }
Please login to merge, or discard this patch.
src/Mail.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -25,47 +25,47 @@
 block discarded – undo
25 25
 interface Mail extends Renderable
26 26
 {
27 27
 
28
-    /**
29
-     * Set the template that the email will use.
30
-     *
31
-     * @since 1.0.0
32
-     *
33
-     * @param string|Template $template Template to use.
34
-     *
35
-     * @return Mail
36
-     */
37
-    public function setTemplate($template);
28
+	/**
29
+	 * Set the template that the email will use.
30
+	 *
31
+	 * @since 1.0.0
32
+	 *
33
+	 * @param string|Template $template Template to use.
34
+	 *
35
+	 * @return Mail
36
+	 */
37
+	public function setTemplate($template);
38 38
 
39
-    /**
40
-     * Get the instance of the template.
41
-     *
42
-     * @since 1.0.0
43
-     *
44
-     * @return Template
45
-     */
46
-    public function getTemplate();
39
+	/**
40
+	 * Get the instance of the template.
41
+	 *
42
+	 * @since 1.0.0
43
+	 *
44
+	 * @return Template
45
+	 */
46
+	public function getTemplate();
47 47
 
48
-    /**
49
-     * Add a section to the Mail.
50
-     *
51
-     * @since 1.0.0
52
-     *
53
-     * @param string $type    Type of section to add.
54
-     * @param string $content Content of the section.
55
-     *
56
-     * @return Mail
57
-     * @throws RuntimeException
58
-     */
59
-    public function addSection($type, $content);
48
+	/**
49
+	 * Add a section to the Mail.
50
+	 *
51
+	 * @since 1.0.0
52
+	 *
53
+	 * @param string $type    Type of section to add.
54
+	 * @param string $content Content of the section.
55
+	 *
56
+	 * @return Mail
57
+	 * @throws RuntimeException
58
+	 */
59
+	public function addSection($type, $content);
60 60
 
61
-    /**
62
-     * Send the email to one or more recipients.
63
-     *
64
-     * @since 1.0.0
65
-     *
66
-     * @param Recipients|EmailAddress|array|string $recipients
67
-     *
68
-     * @return Mail
69
-     */
70
-    public function sendTo($recipients);
61
+	/**
62
+	 * Send the email to one or more recipients.
63
+	 *
64
+	 * @since 1.0.0
65
+	 *
66
+	 * @param Recipients|EmailAddress|array|string $recipients
67
+	 *
68
+	 * @return Mail
69
+	 */
70
+	public function sendTo($recipients);
71 71
 }
Please login to merge, or discard this patch.
src/Support/EmailAddress.php 2 patches
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -25,79 +25,79 @@
 block discarded – undo
25 25
 class EmailAddress
26 26
 {
27 27
 
28
-    /**
29
-     * The local part of the email address (before the '@' sign).
30
-     *
31
-     * @var string
32
-     */
33
-    protected $localPart;
28
+	/**
29
+	 * The local part of the email address (before the '@' sign).
30
+	 *
31
+	 * @var string
32
+	 */
33
+	protected $localPart;
34 34
 
35
-    /**
36
-     * The domain part of the email address (after the '@' sign).
37
-     *
38
-     * @var Domain
39
-     */
40
-    protected $domain;
35
+	/**
36
+	 * The domain part of the email address (after the '@' sign).
37
+	 *
38
+	 * @var Domain
39
+	 */
40
+	protected $domain;
41 41
 
42
-    /**
43
-     * Instantiate an EmailAddress object.
44
-     *
45
-     * @param EmailAddress|string $email The email to parse.
46
-     *
47
-     * @throws InvalidEmailAddress If the email is not valid.
48
-     */
49
-    public function __construct($email)
50
-    {
51
-        if (false === filter_var($email, FILTER_VALIDATE_EMAIL)) {
52
-            throw InvalidEmailAddress::from($email);
53
-        }
42
+	/**
43
+	 * Instantiate an EmailAddress object.
44
+	 *
45
+	 * @param EmailAddress|string $email The email to parse.
46
+	 *
47
+	 * @throws InvalidEmailAddress If the email is not valid.
48
+	 */
49
+	public function __construct($email)
50
+	{
51
+		if (false === filter_var($email, FILTER_VALIDATE_EMAIL)) {
52
+			throw InvalidEmailAddress::from($email);
53
+		}
54 54
 
55
-        try {
56
-            $parts           = explode('@', $email);
57
-            $this->localPart = trim($parts[0]);
58
-            $this->domain    = new Domain(trim($parts[1]));
59
-        } catch (Exception $exception) {
60
-            throw InvalidEmailAddress::from($email);
61
-        }
62
-    }
55
+		try {
56
+			$parts           = explode('@', $email);
57
+			$this->localPart = trim($parts[0]);
58
+			$this->domain    = new Domain(trim($parts[1]));
59
+		} catch (Exception $exception) {
60
+			throw InvalidEmailAddress::from($email);
61
+		}
62
+	}
63 63
 
64
-    /**
65
-     * Returns the local part of the email address.
66
-     *
67
-     * @return string
68
-     */
69
-    public function getLocalPart()
70
-    {
71
-        return $this->localPart;
72
-    }
64
+	/**
65
+	 * Returns the local part of the email address.
66
+	 *
67
+	 * @return string
68
+	 */
69
+	public function getLocalPart()
70
+	{
71
+		return $this->localPart;
72
+	}
73 73
 
74
-    /**
75
-     * Returns the domain part of the email address.
76
-     *
77
-     * @return Domain
78
-     */
79
-    public function getDomainPart()
80
-    {
81
-        return $this->domain;
82
-    }
74
+	/**
75
+	 * Returns the domain part of the email address.
76
+	 *
77
+	 * @return Domain
78
+	 */
79
+	public function getDomainPart()
80
+	{
81
+		return $this->domain;
82
+	}
83 83
 
84
-    /**
85
-     * Returns the entire email address.
86
-     *
87
-     * @return string
88
-     */
89
-    public function getAddress()
90
-    {
91
-        return $this->getLocalPart() . '@' . $this->getDomainPart();
92
-    }
84
+	/**
85
+	 * Returns the entire email address.
86
+	 *
87
+	 * @return string
88
+	 */
89
+	public function getAddress()
90
+	{
91
+		return $this->getLocalPart() . '@' . $this->getDomainPart();
92
+	}
93 93
 
94
-    /**
95
-     * Convert the EmailAddress object to a string.
96
-     *
97
-     * @return string
98
-     */
99
-    public function __toString()
100
-    {
101
-        return $this->getAddress();
102
-    }
94
+	/**
95
+	 * Convert the EmailAddress object to a string.
96
+	 *
97
+	 * @return string
98
+	 */
99
+	public function __toString()
100
+	{
101
+		return $this->getAddress();
102
+	}
103 103
 }
104 104
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@
 block discarded – undo
88 88
      */
89 89
     public function getAddress()
90 90
     {
91
-        return $this->getLocalPart() . '@' . $this->getDomainPart();
91
+        return $this->getLocalPart().'@'.$this->getDomainPart();
92 92
     }
93 93
 
94 94
     /**
Please login to merge, or discard this patch.