Passed
Push — master ( a2b844...4633d8 )
by Alain
02:21
created
src/Mail.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -24,36 +24,36 @@
 block discarded – undo
24 24
 interface Mail 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|Template $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|Template $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 Template
44
-     */
45
-    public function getTemplate();
38
+	/**
39
+	 * Get the instance of the template.
40
+	 *
41
+	 * @since 1.0.0
42
+	 *
43
+	 * @return Template
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
 }
Please login to merge, or discard this patch.
src/Validator.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -22,15 +22,15 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
src/Section/AbstractSection.php 1 patch
Indentation   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -28,145 +28,145 @@
 block discarded – undo
28 28
 abstract class AbstractSection implements Section
29 29
 {
30 30
 
31
-    /**
32
-     * Name of the Section.
33
-     *
34
-     * @since 1.0.0
35
-     *
36
-     * @var string
37
-     */
38
-    protected $sectionName;
39
-
40
-    /**
41
-     * Configuration Settings.
42
-     *
43
-     * @since 1.0.0
44
-     *
45
-     * @var ConfigInterface
46
-     */
47
-    protected $config;
48
-
49
-    /**
50
-     * Content of the section.
51
-     *
52
-     * @since 1.0.0
53
-     *
54
-     * @var string
55
-     */
56
-    protected $content;
57
-
58
-    /**
59
-     * ViewBuilder to create template and section views.
60
-     *
61
-     * @since 1.0.0
62
-     *
63
-     * @var ViewBuilder
64
-     */
65
-    protected $viewBuilder;
66
-
67
-    /**
68
-     * Instantiate a AbstractSection object.
69
-     *
70
-     * @since 1.0.0
71
-     *
72
-     * @param ConfigInterface $config    Configuration settings.
73
-     * @param array           $arguments Arguments that are passed through the constructor.
74
-     *                                   Contained elements:
75
-     *                                   string $section, string $content
76
-     *
77
-     * @throws RuntimeException
78
-     */
79
-    public function __construct($config, array $arguments)
80
-    {
81
-        $this->config = $config;
82
-        list($section, $content, $this->viewBuilder) = $arguments;
83
-        $this->setSectionName($section);
84
-        $this->content = $content;
85
-    }
86
-
87
-    /**
88
-     * Get the name of the Section.
89
-     *
90
-     * @since 1.0.0
91
-     *
92
-     * @return string Name of the section.
93
-     */
94
-    public function getSectionName()
95
-    {
96
-        return $this->sectionName;
97
-    }
98
-
99
-    /**
100
-     * Set the name of the Section.
101
-     *
102
-     * @since 1.0.0
103
-     *
104
-     * @param string|null $section Optional. Name of the section.
105
-     *
106
-     * @throws FailedToInitialiseSection If no section name was passed.
107
-     * @throws FailedToInitialiseSection If an unknown section name was passed.
108
-     */
109
-    protected function setSectionName($section = null)
110
-    {
111
-        if (null === $section) {
112
-            throw new FailedToInitialiseSection(
113
-                'Initialised section without passing it a section name.'
114
-            );
115
-        }
116
-        if ( ! array_key_exists($section, $this->config['sections'])) {
117
-            throw new FailedToInitialiseSection(
118
-                'Initialised section with an unknown section name.'
119
-            );
120
-        }
121
-        $this->sectionName = $section;
122
-    }
123
-
124
-    /**
125
-     * Render the current Renderable for a given context.
126
-     *
127
-     * @since 1.0.0
128
-     *
129
-     * @param array $context The context in which to render the Renderable.
130
-     *
131
-     * @return string Rendered output of the Renderable.
132
-     * @throws RuntimeException
133
-     */
134
-    public function render(array $context)
135
-    {
136
-
137
-        $viewName = $this->getViewName($context);
138
-        $view     = $this->viewBuilder->create($viewName);
139
-
140
-        $context['css_class'] = $this->getCSSClass();
141
-        $context['content']   = $this->content;
142
-
143
-        return $view->render($context);
144
-    }
145
-
146
-    /**
147
-     * Get the name of the View to use for rendering.
148
-     *
149
-     * @since 1.0.0
150
-     *
151
-     * @param array $context The context in which to render the template.
152
-     *
153
-     * @return string Name of the view.
154
-     */
155
-    protected function getViewName(array $context)
156
-    {
157
-        return $this->config['sections'][$this->getSectionName()]['view_name']
158
-               . '.' . $context['format'];
159
-    }
160
-
161
-    /**
162
-     * Get the CSS class that is used for the section.
163
-     *
164
-     * @since 1.0.0
165
-     *
166
-     * @return string
167
-     */
168
-    protected function getCSSClass()
169
-    {
170
-        return $this->config['sections'][$this->getSectionName()]['css_class'];
171
-    }
31
+	/**
32
+	 * Name of the Section.
33
+	 *
34
+	 * @since 1.0.0
35
+	 *
36
+	 * @var string
37
+	 */
38
+	protected $sectionName;
39
+
40
+	/**
41
+	 * Configuration Settings.
42
+	 *
43
+	 * @since 1.0.0
44
+	 *
45
+	 * @var ConfigInterface
46
+	 */
47
+	protected $config;
48
+
49
+	/**
50
+	 * Content of the section.
51
+	 *
52
+	 * @since 1.0.0
53
+	 *
54
+	 * @var string
55
+	 */
56
+	protected $content;
57
+
58
+	/**
59
+	 * ViewBuilder to create template and section views.
60
+	 *
61
+	 * @since 1.0.0
62
+	 *
63
+	 * @var ViewBuilder
64
+	 */
65
+	protected $viewBuilder;
66
+
67
+	/**
68
+	 * Instantiate a AbstractSection object.
69
+	 *
70
+	 * @since 1.0.0
71
+	 *
72
+	 * @param ConfigInterface $config    Configuration settings.
73
+	 * @param array           $arguments Arguments that are passed through the constructor.
74
+	 *                                   Contained elements:
75
+	 *                                   string $section, string $content
76
+	 *
77
+	 * @throws RuntimeException
78
+	 */
79
+	public function __construct($config, array $arguments)
80
+	{
81
+		$this->config = $config;
82
+		list($section, $content, $this->viewBuilder) = $arguments;
83
+		$this->setSectionName($section);
84
+		$this->content = $content;
85
+	}
86
+
87
+	/**
88
+	 * Get the name of the Section.
89
+	 *
90
+	 * @since 1.0.0
91
+	 *
92
+	 * @return string Name of the section.
93
+	 */
94
+	public function getSectionName()
95
+	{
96
+		return $this->sectionName;
97
+	}
98
+
99
+	/**
100
+	 * Set the name of the Section.
101
+	 *
102
+	 * @since 1.0.0
103
+	 *
104
+	 * @param string|null $section Optional. Name of the section.
105
+	 *
106
+	 * @throws FailedToInitialiseSection If no section name was passed.
107
+	 * @throws FailedToInitialiseSection If an unknown section name was passed.
108
+	 */
109
+	protected function setSectionName($section = null)
110
+	{
111
+		if (null === $section) {
112
+			throw new FailedToInitialiseSection(
113
+				'Initialised section without passing it a section name.'
114
+			);
115
+		}
116
+		if ( ! array_key_exists($section, $this->config['sections'])) {
117
+			throw new FailedToInitialiseSection(
118
+				'Initialised section with an unknown section name.'
119
+			);
120
+		}
121
+		$this->sectionName = $section;
122
+	}
123
+
124
+	/**
125
+	 * Render the current Renderable for a given context.
126
+	 *
127
+	 * @since 1.0.0
128
+	 *
129
+	 * @param array $context The context in which to render the Renderable.
130
+	 *
131
+	 * @return string Rendered output of the Renderable.
132
+	 * @throws RuntimeException
133
+	 */
134
+	public function render(array $context)
135
+	{
136
+
137
+		$viewName = $this->getViewName($context);
138
+		$view     = $this->viewBuilder->create($viewName);
139
+
140
+		$context['css_class'] = $this->getCSSClass();
141
+		$context['content']   = $this->content;
142
+
143
+		return $view->render($context);
144
+	}
145
+
146
+	/**
147
+	 * Get the name of the View to use for rendering.
148
+	 *
149
+	 * @since 1.0.0
150
+	 *
151
+	 * @param array $context The context in which to render the template.
152
+	 *
153
+	 * @return string Name of the view.
154
+	 */
155
+	protected function getViewName(array $context)
156
+	{
157
+		return $this->config['sections'][$this->getSectionName()]['view_name']
158
+			   . '.' . $context['format'];
159
+	}
160
+
161
+	/**
162
+	 * Get the CSS class that is used for the section.
163
+	 *
164
+	 * @since 1.0.0
165
+	 *
166
+	 * @return string
167
+	 */
168
+	protected function getCSSClass()
169
+	{
170
+		return $this->config['sections'][$this->getSectionName()]['css_class'];
171
+	}
172 172
 }
Please login to merge, or discard this patch.
src/Sanitizer.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -22,15 +22,15 @@
 block discarded – undo
22 22
 interface SanitizerInterface
23 23
 {
24 24
 
25
-    /**
26
-     * Sanitize 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
-     *
33
-     * @return string Sanitized content.
34
-     */
35
-    public function sanitize($content, array $context);
25
+	/**
26
+	 * Sanitize 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
+	 *
33
+	 * @return string Sanitized content.
34
+	 */
35
+	public function sanitize($content, array $context);
36 36
 }
Please login to merge, or discard this patch.
src/Template.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -22,21 +22,21 @@
 block discarded – undo
22 22
 interface TemplateInterface extends Renderable
23 23
 {
24 24
 
25
-    /**
26
-     * Get an array of Sections that are used by this template.
27
-     *
28
-     * @since 1.0.0
29
-     *
30
-     * @return array Sections that are used by this template.
31
-     */
32
-    public function getUsedSections();
25
+	/**
26
+	 * Get an array of Sections that are used by this template.
27
+	 *
28
+	 * @since 1.0.0
29
+	 *
30
+	 * @return array Sections that are used by this template.
31
+	 */
32
+	public function getUsedSections();
33 33
 
34
-    /**
35
-     * Get the name of the Template.
36
-     *
37
-     * @since 1.0.0
38
-     *
39
-     * @return string Name of the template.
40
-     */
41
-    public function getTemplateName();
34
+	/**
35
+	 * Get the name of the Template.
36
+	 *
37
+	 * @since 1.0.0
38
+	 *
39
+	 * @return string Name of the template.
40
+	 */
41
+	public function getTemplateName();
42 42
 }
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_merge(
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_merge(
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/Section.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -22,12 +22,12 @@
 block discarded – undo
22 22
 interface SectionInterface extends Renderable
23 23
 {
24 24
 
25
-    /**
26
-     * Get the name of the Section.
27
-     *
28
-     * @since 1.0.0
29
-     *
30
-     * @return string Name of the section.
31
-     */
32
-    public function getSectionName();
25
+	/**
26
+	 * Get the name of the Section.
27
+	 *
28
+	 * @since 1.0.0
29
+	 *
30
+	 * @return string Name of the section.
31
+	 */
32
+	public function getSectionName();
33 33
 }
Please login to merge, or discard this patch.
src/Mail/AbstractMail.php 1 patch
Indentation   +254 added lines, -254 removed lines patch added patch discarded remove patch
@@ -34,258 +34,258 @@
 block discarded – undo
34 34
 abstract class AbstractMail implements Mail
35 35
 {
36 36
 
37
-    /**
38
-     * Configuration Settings.
39
-     *
40
-     * @since 1.0.0
41
-     *
42
-     * @var ConfigInterface
43
-     */
44
-    protected $config;
45
-
46
-    /**
47
-     * Template that is used for the email.
48
-     *
49
-     * @since 1.0.0
50
-     *
51
-     * @var Template
52
-     */
53
-    protected $template;
54
-
55
-    /**
56
-     * Content for the different sections.
57
-     *
58
-     * @since 1.0.0
59
-     *
60
-     * @var array
61
-     */
62
-    protected $sectionContent = [];
63
-
64
-    /**
65
-     * Format of the mail.
66
-     *
67
-     * @since 1.0.0
68
-     *
69
-     * @var string
70
-     */
71
-    protected $format;
72
-
73
-    /**
74
-     * ViewBuilder to create template and section views.
75
-     *
76
-     * @since 1.0.0
77
-     *
78
-     * @var ViewBuilder
79
-     */
80
-    protected $viewBuilder;
81
-
82
-    /**
83
-     * Instantiate an AbstractMail object.
84
-     *
85
-     * @since 1.0.0
86
-     *
87
-     * @param ConfigInterface $config The Config to use.
88
-     *
89
-     * @throws FailedToProcessConfigException If the Config could not be processed.
90
-     */
91
-    public function __construct(ConfigInterface $config)
92
-    {
93
-        $this->config = $config;
94
-        $this->setFormat();
95
-
96
-        $this->viewBuilder = new ViewBuilder($config
97
-            ? $config->getSubConfig('ViewBuilder')
98
-            : View::getDefaultConfig()
99
-        );
100
-
101
-        foreach ($this->config->getKey('view_root_locations') as $folder) {
102
-            $this->viewBuilder->addLocation(
103
-                new FilesystemLocation($folder)
104
-            );
105
-        }
106
-    }
107
-
108
-    /**
109
-     * Get the template to use for the renderer.
110
-     *
111
-     * @since 1.0.0
112
-     *
113
-     * @return Template Reference to the template that is used.
114
-     * @throws RuntimeException
115
-     */
116
-    public function getTemplate()
117
-    {
118
-
119
-        if ( ! $this->template) {
120
-            $this->setDefaultTemplate();
121
-        }
122
-
123
-        if (is_string($this->template)) {
124
-            $this->template = $this->createTemplate($this->template);
125
-        }
126
-
127
-        return $this->template;
128
-    }
129
-
130
-    /**
131
-     * Set the template to use for the renderer.
132
-     *
133
-     * @since 1.0.0
134
-     *
135
-     * @param string|Template $template          Template to use for the
136
-     *                                           renderer.
137
-     *
138
-     * @throws InvalidTemplate If the template class could not be instantiated.
139
-     * @throws InvalidTemplate If the template type is not recognized.
140
-     */
141
-    public function setTemplate($template)
142
-    {
143
-        try {
144
-            if (is_string($template)) {
145
-                $template = $this->createTemplate($template);
146
-            }
147
-        } catch (Exception $exception) {
148
-            throw new InvalidTemplate(
149
-                'Could not instantiate the template class "%1$s". Reason: "%2$s".',
150
-                $template,
151
-                $exception->getMessage()
152
-            );
153
-        }
154
-
155
-        if ( ! $template instanceof Template) {
156
-            throw new InvalidTemplate(
157
-                'Could not set the template, invalid type.',
158
-                (array)$template
159
-            );
160
-        }
161
-        $this->template = $template;
162
-    }
163
-
164
-    /**
165
-     * Add a section to the Mail.
166
-     *
167
-     * @since 1.0.0
168
-     *
169
-     * @param string $type    Type of section to add.
170
-     * @param string $content Content of the section.
171
-     *
172
-     * @throws RuntimeException
173
-     */
174
-    public function addSection($type, $content)
175
-    {
176
-        $this->sectionContent[$type] = $content;
177
-    }
178
-
179
-    /**
180
-     * Render the Mail for a given context.
181
-     *
182
-     * @since 1.0.0
183
-     *
184
-     * @param array $context The context in which to render the email.
185
-     *
186
-     * @return string Rendered output of the email
187
-     */
188
-    public function render(array $context)
189
-    {
190
-        $template = $this->getTemplate();
191
-
192
-        $context['template'] = $template;
193
-
194
-        $this->instantiateSections($template->getUsedSections(), $context);
195
-
196
-        $context['format'] = $this->getFormat();
197
-
198
-        $context = $this->setContext($context);
199
-
200
-        return $template->render($context);
201
-    }
202
-
203
-    /**
204
-     * Instantiate the requested sections for a template.
205
-     *
206
-     * @since 1.0.0
207
-     *
208
-     * @param array $sections Sections to instantiate.
209
-     * @param array $context  The context in which to instantiate the sections.
210
-     */
211
-    protected function instantiateSections(array $sections, array &$context)
212
-    {
213
-        $sectionFactory = new Factory($this->config, 'sections');
214
-
215
-        foreach ($sections as $section) {
216
-
217
-            $content = null;
218
-
219
-            if (array_key_exists($section, $this->sectionContent)) {
220
-                $content = $this->sectionContent[$section];
221
-            }
222
-
223
-            $context['sections'][$section] = $sectionFactory->create(
224
-                $section,
225
-                [$section, $content, $this->viewBuilder]
226
-            );
227
-        }
228
-    }
229
-
230
-    /**
231
-     * Set the format of the mail.
232
-     *
233
-     * @since 1.0.0
234
-     *
235
-     * @return string Format of the Mail.
236
-     */
237
-    protected function getFormat()
238
-    {
239
-        return $this->format;
240
-    }
241
-
242
-    /**
243
-     * Set the format of the mail.
244
-     *
245
-     * @since 1.0.0
246
-     *
247
-     * @return void
248
-     */
249
-    abstract protected function setFormat();
250
-
251
-    /**
252
-     * Set the template to the default template defined in the configuration.
253
-     *
254
-     * @since 1.0.0
255
-     *
256
-     * @throws RuntimeException
257
-     */
258
-    protected function setDefaultTemplate()
259
-    {
260
-        $defaultTemplate = $this->config->getKey('default_template');
261
-        $this->setTemplate($defaultTemplate);
262
-    }
263
-
264
-    /**
265
-     * Create an instance of a template.
266
-     *
267
-     * @since 1.0.0
268
-     *
269
-     * @param string $template Template to instantiate.
270
-     *
271
-     * @return Template $template Newly created instance.
272
-     * @throws RuntimeException
273
-     */
274
-    protected function createTemplate($template)
275
-    {
276
-        $templateFactory = new Factory($this->config, 'templates');
277
-
278
-        return $templateFactory->create($template, [$template, $this->viewBuilder]);
279
-    }
280
-
281
-    /**
282
-     * Set the context of the mail.
283
-     *
284
-     * @since 1.0.0
285
-     *
286
-     * @param array $context Context to set/modify.
287
-     *
288
-     * @return array Updated context.
289
-     */
290
-    abstract protected function setContext(array $context);
37
+	/**
38
+	 * Configuration Settings.
39
+	 *
40
+	 * @since 1.0.0
41
+	 *
42
+	 * @var ConfigInterface
43
+	 */
44
+	protected $config;
45
+
46
+	/**
47
+	 * Template that is used for the email.
48
+	 *
49
+	 * @since 1.0.0
50
+	 *
51
+	 * @var Template
52
+	 */
53
+	protected $template;
54
+
55
+	/**
56
+	 * Content for the different sections.
57
+	 *
58
+	 * @since 1.0.0
59
+	 *
60
+	 * @var array
61
+	 */
62
+	protected $sectionContent = [];
63
+
64
+	/**
65
+	 * Format of the mail.
66
+	 *
67
+	 * @since 1.0.0
68
+	 *
69
+	 * @var string
70
+	 */
71
+	protected $format;
72
+
73
+	/**
74
+	 * ViewBuilder to create template and section views.
75
+	 *
76
+	 * @since 1.0.0
77
+	 *
78
+	 * @var ViewBuilder
79
+	 */
80
+	protected $viewBuilder;
81
+
82
+	/**
83
+	 * Instantiate an AbstractMail object.
84
+	 *
85
+	 * @since 1.0.0
86
+	 *
87
+	 * @param ConfigInterface $config The Config to use.
88
+	 *
89
+	 * @throws FailedToProcessConfigException If the Config could not be processed.
90
+	 */
91
+	public function __construct(ConfigInterface $config)
92
+	{
93
+		$this->config = $config;
94
+		$this->setFormat();
95
+
96
+		$this->viewBuilder = new ViewBuilder($config
97
+			? $config->getSubConfig('ViewBuilder')
98
+			: View::getDefaultConfig()
99
+		);
100
+
101
+		foreach ($this->config->getKey('view_root_locations') as $folder) {
102
+			$this->viewBuilder->addLocation(
103
+				new FilesystemLocation($folder)
104
+			);
105
+		}
106
+	}
107
+
108
+	/**
109
+	 * Get the template to use for the renderer.
110
+	 *
111
+	 * @since 1.0.0
112
+	 *
113
+	 * @return Template Reference to the template that is used.
114
+	 * @throws RuntimeException
115
+	 */
116
+	public function getTemplate()
117
+	{
118
+
119
+		if ( ! $this->template) {
120
+			$this->setDefaultTemplate();
121
+		}
122
+
123
+		if (is_string($this->template)) {
124
+			$this->template = $this->createTemplate($this->template);
125
+		}
126
+
127
+		return $this->template;
128
+	}
129
+
130
+	/**
131
+	 * Set the template to use for the renderer.
132
+	 *
133
+	 * @since 1.0.0
134
+	 *
135
+	 * @param string|Template $template          Template to use for the
136
+	 *                                           renderer.
137
+	 *
138
+	 * @throws InvalidTemplate If the template class could not be instantiated.
139
+	 * @throws InvalidTemplate If the template type is not recognized.
140
+	 */
141
+	public function setTemplate($template)
142
+	{
143
+		try {
144
+			if (is_string($template)) {
145
+				$template = $this->createTemplate($template);
146
+			}
147
+		} catch (Exception $exception) {
148
+			throw new InvalidTemplate(
149
+				'Could not instantiate the template class "%1$s". Reason: "%2$s".',
150
+				$template,
151
+				$exception->getMessage()
152
+			);
153
+		}
154
+
155
+		if ( ! $template instanceof Template) {
156
+			throw new InvalidTemplate(
157
+				'Could not set the template, invalid type.',
158
+				(array)$template
159
+			);
160
+		}
161
+		$this->template = $template;
162
+	}
163
+
164
+	/**
165
+	 * Add a section to the Mail.
166
+	 *
167
+	 * @since 1.0.0
168
+	 *
169
+	 * @param string $type    Type of section to add.
170
+	 * @param string $content Content of the section.
171
+	 *
172
+	 * @throws RuntimeException
173
+	 */
174
+	public function addSection($type, $content)
175
+	{
176
+		$this->sectionContent[$type] = $content;
177
+	}
178
+
179
+	/**
180
+	 * Render the Mail for a given context.
181
+	 *
182
+	 * @since 1.0.0
183
+	 *
184
+	 * @param array $context The context in which to render the email.
185
+	 *
186
+	 * @return string Rendered output of the email
187
+	 */
188
+	public function render(array $context)
189
+	{
190
+		$template = $this->getTemplate();
191
+
192
+		$context['template'] = $template;
193
+
194
+		$this->instantiateSections($template->getUsedSections(), $context);
195
+
196
+		$context['format'] = $this->getFormat();
197
+
198
+		$context = $this->setContext($context);
199
+
200
+		return $template->render($context);
201
+	}
202
+
203
+	/**
204
+	 * Instantiate the requested sections for a template.
205
+	 *
206
+	 * @since 1.0.0
207
+	 *
208
+	 * @param array $sections Sections to instantiate.
209
+	 * @param array $context  The context in which to instantiate the sections.
210
+	 */
211
+	protected function instantiateSections(array $sections, array &$context)
212
+	{
213
+		$sectionFactory = new Factory($this->config, 'sections');
214
+
215
+		foreach ($sections as $section) {
216
+
217
+			$content = null;
218
+
219
+			if (array_key_exists($section, $this->sectionContent)) {
220
+				$content = $this->sectionContent[$section];
221
+			}
222
+
223
+			$context['sections'][$section] = $sectionFactory->create(
224
+				$section,
225
+				[$section, $content, $this->viewBuilder]
226
+			);
227
+		}
228
+	}
229
+
230
+	/**
231
+	 * Set the format of the mail.
232
+	 *
233
+	 * @since 1.0.0
234
+	 *
235
+	 * @return string Format of the Mail.
236
+	 */
237
+	protected function getFormat()
238
+	{
239
+		return $this->format;
240
+	}
241
+
242
+	/**
243
+	 * Set the format of the mail.
244
+	 *
245
+	 * @since 1.0.0
246
+	 *
247
+	 * @return void
248
+	 */
249
+	abstract protected function setFormat();
250
+
251
+	/**
252
+	 * Set the template to the default template defined in the configuration.
253
+	 *
254
+	 * @since 1.0.0
255
+	 *
256
+	 * @throws RuntimeException
257
+	 */
258
+	protected function setDefaultTemplate()
259
+	{
260
+		$defaultTemplate = $this->config->getKey('default_template');
261
+		$this->setTemplate($defaultTemplate);
262
+	}
263
+
264
+	/**
265
+	 * Create an instance of a template.
266
+	 *
267
+	 * @since 1.0.0
268
+	 *
269
+	 * @param string $template Template to instantiate.
270
+	 *
271
+	 * @return Template $template Newly created instance.
272
+	 * @throws RuntimeException
273
+	 */
274
+	protected function createTemplate($template)
275
+	{
276
+		$templateFactory = new Factory($this->config, 'templates');
277
+
278
+		return $templateFactory->create($template, [$template, $this->viewBuilder]);
279
+	}
280
+
281
+	/**
282
+	 * Set the context of the mail.
283
+	 *
284
+	 * @since 1.0.0
285
+	 *
286
+	 * @param array $context Context to set/modify.
287
+	 *
288
+	 * @return array Updated context.
289
+	 */
290
+	abstract protected function setContext(array $context);
291 291
 }
Please login to merge, or discard this patch.
src/Support/Factory.php 1 patch
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -26,75 +26,75 @@
 block discarded – undo
26 26
 class Factory
27 27
 {
28 28
 
29
-    /**
30
-     * Configuration Settings.
31
-     *
32
-     * @since 1.0.0
33
-     *
34
-     * @var ConfigInterface
35
-     */
36
-    protected $config;
29
+	/**
30
+	 * Configuration Settings.
31
+	 *
32
+	 * @since 1.0.0
33
+	 *
34
+	 * @var ConfigInterface
35
+	 */
36
+	protected $config;
37 37
 
38
-    /**
39
-     * Type of element the factory wants to create.
40
-     *
41
-     * @since 1.0.0
42
-     *
43
-     * @var string
44
-     */
45
-    protected $element;
38
+	/**
39
+	 * Type of element the factory wants to create.
40
+	 *
41
+	 * @since 1.0.0
42
+	 *
43
+	 * @var string
44
+	 */
45
+	protected $element;
46 46
 
47
-    /**
48
-     * Instantiate a Factory object.
49
-     *
50
-     * @since 1.0.0
51
-     *
52
-     * @param ConfigInterface $config  Configuration settings.
53
-     * @param string          $element The type of element to instantiate a factory for.
54
-     *
55
-     * @throws FailedToInstantiateFactory When an unknown element type is requested.
56
-     */
57
-    public function __construct(ConfigInterface $config, $element)
58
-    {
47
+	/**
48
+	 * Instantiate a Factory object.
49
+	 *
50
+	 * @since 1.0.0
51
+	 *
52
+	 * @param ConfigInterface $config  Configuration settings.
53
+	 * @param string          $element The type of element to instantiate a factory for.
54
+	 *
55
+	 * @throws FailedToInstantiateFactory When an unknown element type is requested.
56
+	 */
57
+	public function __construct(ConfigInterface $config, $element)
58
+	{
59 59
 
60
-        $this->config = $config;
60
+		$this->config = $config;
61 61
 
62
-        if ( ! $this->config->hasKey($element)) {
63
-            throw new FailedToInstantiateFactory(sprintf(
64
-                'Could not instantiate Factory for unknown Element Type "%1$s".',
65
-                $element
66
-            ));
67
-        }
62
+		if ( ! $this->config->hasKey($element)) {
63
+			throw new FailedToInstantiateFactory(sprintf(
64
+				'Could not instantiate Factory for unknown Element Type "%1$s".',
65
+				$element
66
+			));
67
+		}
68 68
 
69
-        $this->element = $element;
70
-    }
69
+		$this->element = $element;
70
+	}
71 71
 
72
-    /**
73
-     * Create and return a new instance of an element.
74
-     *
75
-     * @since 1.0.0
76
-     *
77
-     * @param string $type      Type of element to create.
78
-     * @param mixed  $arguments Optional. Arguments to pass to the object.
79
-     *
80
-     * @return object New instance of the requested class.
81
-     * @throws FailedToInstantiateClass If an unknown element type is requested.
82
-     */
83
-    public function create($type, $arguments = null)
84
-    {
72
+	/**
73
+	 * Create and return a new instance of an element.
74
+	 *
75
+	 * @since 1.0.0
76
+	 *
77
+	 * @param string $type      Type of element to create.
78
+	 * @param mixed  $arguments Optional. Arguments to pass to the object.
79
+	 *
80
+	 * @return object New instance of the requested class.
81
+	 * @throws FailedToInstantiateClass If an unknown element type is requested.
82
+	 */
83
+	public function create($type, $arguments = null)
84
+	{
85 85
 
86
-        $classMap = $this->config[$this->element];
86
+		$classMap = $this->config[$this->element];
87 87
 
88
-        if ( ! array_key_exists($type, $classMap)) {
89
-            throw new FailedToInstantiateClass(sprintf(
90
-                'Could not create object, unknown Type "%1$s" for "%2$s" elements.',
91
-                $type,
92
-                $this->element
93
-            ));
94
-        }
88
+		if ( ! array_key_exists($type, $classMap)) {
89
+			throw new FailedToInstantiateClass(sprintf(
90
+				'Could not create object, unknown Type "%1$s" for "%2$s" elements.',
91
+				$type,
92
+				$this->element
93
+			));
94
+		}
95 95
 
96
-        $className = $classMap[$type]['class_name'];
96
+		$className = $classMap[$type]['class_name'];
97 97
 
98
-        return new $className($this->config, $arguments);
99
-    }
98
+		return new $className($this->config, $arguments);
99
+	}
100 100
 }
Please login to merge, or discard this patch.