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