Passed
Push — master ( be0c82...f539f4 )
by Alain
02:33
created
config/defaults.php 2 patches
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -16,175 +16,175 @@
 block discarded – undo
16 16
  * `ConfigInterface` to the `ChainMail` constructor.
17 17
  */
18 18
 return [
19
-    /*
19
+	/*
20 20
      * Root location that contains the view files to be rendered. These are
21 21
      * referenced by the individual sections & templates when choosing a
22 22
      * specific view to be rendered.
23 23
      */
24
-    'view_root_locations' => [
25
-        'default' => realpath(__DIR__ . '/../views'),
26
-    ],
24
+	'view_root_locations' => [
25
+		'default' => realpath(__DIR__ . '/../views'),
26
+	],
27 27
 
28
-    /*
28
+	/*
29 29
      * The default template to when none is specified.
30 30
      */
31
-    'default_template'    => 'BasicTemplate',
31
+	'default_template'    => 'BasicTemplate',
32 32
 
33
-    /*
33
+	/*
34 34
      * The formats in which an email can be rendered.
35 35
      * Each format needs a `Mail` implementation, a
36 36
      * `Validator` implementation, as well as a `Sanitizer`
37 37
      * implementation.
38 38
      */
39
-    'formats'             => [
39
+	'formats'             => [
40 40
 
41
-        /*
41
+		/*
42 42
          * The `html` format should be the default format when using responsive
43 43
          * emails.
44 44
          */
45
-        'html' => [
46
-            'mail'      => 'HTMLMail',
47
-            'validator' => 'HTMLValidator',
48
-            'sanitizer' => 'HTMLSanitizer',
49
-        ],
45
+		'html' => [
46
+			'mail'      => 'HTMLMail',
47
+			'validator' => 'HTMLValidator',
48
+			'sanitizer' => 'HTMLSanitizer',
49
+		],
50 50
 
51
-        /*
51
+		/*
52 52
          * The `text` format is meant to be used a as a fallback, and can also
53 53
          * be sent as backup content embedded within HTML emails.
54 54
          */
55
-        'text' => [
56
-            'mail'      => 'TextMail',
57
-            'validator' => 'TextValidator',
58
-            'sanitizer' => 'TextSanitizer',
59
-        ],
60
-    ],
55
+		'text' => [
56
+			'mail'      => 'TextMail',
57
+			'validator' => 'TextValidator',
58
+			'sanitizer' => 'TextSanitizer',
59
+		],
60
+	],
61 61
 
62
-    /*
62
+	/*
63 63
      * The `Mail` implementations that are provided.
64 64
      */
65
-    'mails'               => [
66
-        'HTMLMail' => [
67
-            'class_name' => 'BrightNucleus\ChainMail\Mail\HTMLMail',
68
-        ],
69
-        'TextMail' => [
70
-            'class_name' => 'BrightNucleus\ChainMail\Mail\TextMail',
71
-        ],
72
-    ],
65
+	'mails'               => [
66
+		'HTMLMail' => [
67
+			'class_name' => 'BrightNucleus\ChainMail\Mail\HTMLMail',
68
+		],
69
+		'TextMail' => [
70
+			'class_name' => 'BrightNucleus\ChainMail\Mail\TextMail',
71
+		],
72
+	],
73 73
 
74
-    /*
74
+	/*
75 75
      * The `Validator` implementations that are provided.
76 76
      */
77
-    'validators'          => [
78
-        'HTMLValidator' => [
79
-            'class_name' => 'BrightNucleus\ChainMail\Validator\HTMLValidator',
80
-        ],
81
-        'TextValidator' => [
82
-            'class_name' => 'BrightNucleus\ChainMail\Validator\TextValidator',
83
-        ],
84
-    ],
77
+	'validators'          => [
78
+		'HTMLValidator' => [
79
+			'class_name' => 'BrightNucleus\ChainMail\Validator\HTMLValidator',
80
+		],
81
+		'TextValidator' => [
82
+			'class_name' => 'BrightNucleus\ChainMail\Validator\TextValidator',
83
+		],
84
+	],
85 85
 
86
-    /*
86
+	/*
87 87
      * The `Sanitizer` implementations that are provided.
88 88
      */
89
-    'sanitizers'          => [
90
-        'HTMLSanitizer' => [
91
-            'class_name' => 'BrightNucleus\ChainMail\Sanitizer\HTMLSanitizer',
92
-        ],
93
-        'TextSanitizer' => [
94
-            'class_name' => 'BrightNucleus\ChainMail\Sanitizer\TextSanitizer',
95
-        ],
96
-    ],
89
+	'sanitizers'          => [
90
+		'HTMLSanitizer' => [
91
+			'class_name' => 'BrightNucleus\ChainMail\Sanitizer\HTMLSanitizer',
92
+		],
93
+		'TextSanitizer' => [
94
+			'class_name' => 'BrightNucleus\ChainMail\Sanitizer\TextSanitizer',
95
+		],
96
+	],
97 97
 
98
-    /*
98
+	/*
99 99
      * ViewBuilder configuration that is passed into the `brightnucleus/view` component.
100 100
      */
101
-    'ViewBuilder'         => [
102
-        'ViewFinder' => [
103
-            'Views' => [
104
-                'MailView' => 'BrightNucleus\ChainMail\View\MailView',
105
-            ],
106
-        ],
107
-    ],
101
+	'ViewBuilder'         => [
102
+		'ViewFinder' => [
103
+			'Views' => [
104
+				'MailView' => 'BrightNucleus\ChainMail\View\MailView',
105
+			],
106
+		],
107
+	],
108 108
 
109
-    /*
109
+	/*
110 110
      * The `Template` 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
-        ],
125
-        'HeroTemplate'        => [
126
-            'class_name' => 'BrightNucleus\ChainMail\Template\GenericTemplate',
127
-            'sections'   => [
128
-                'HeaderSection',
129
-                'HeroSection',
130
-                'BodySection',
131
-                'FooterSection',
132
-            ],
133
-            'view_name'  => 'GenericTemplate',
134
-        ],
135
-        'SidebarTemplate'     => [
136
-            'class_name' => 'BrightNucleus\ChainMail\Template\GenericTemplate',
137
-            'sections'   => [
138
-                'HeaderSection',
139
-                'BodySection',
140
-                'SidebarSection',
141
-                'FooterSection',
142
-            ],
143
-            'view_name'  => 'GenericTemplate',
144
-        ],
145
-        'HeroSidebarTemplate' => [
146
-            'class_name' => 'BrightNucleus\ChainMail\Template\GenericTemplate',
147
-            'sections'   => [
148
-                'HeaderSection',
149
-                'HeroSection',
150
-                'BodySection',
151
-                'SidebarSection',
152
-                'FooterSection',
153
-            ],
154
-            'view_name'  => 'GenericTemplate',
155
-        ],
156
-    ],
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
+		],
125
+		'HeroTemplate'        => [
126
+			'class_name' => 'BrightNucleus\ChainMail\Template\GenericTemplate',
127
+			'sections'   => [
128
+				'HeaderSection',
129
+				'HeroSection',
130
+				'BodySection',
131
+				'FooterSection',
132
+			],
133
+			'view_name'  => 'GenericTemplate',
134
+		],
135
+		'SidebarTemplate'     => [
136
+			'class_name' => 'BrightNucleus\ChainMail\Template\GenericTemplate',
137
+			'sections'   => [
138
+				'HeaderSection',
139
+				'BodySection',
140
+				'SidebarSection',
141
+				'FooterSection',
142
+			],
143
+			'view_name'  => 'GenericTemplate',
144
+		],
145
+		'HeroSidebarTemplate' => [
146
+			'class_name' => 'BrightNucleus\ChainMail\Template\GenericTemplate',
147
+			'sections'   => [
148
+				'HeaderSection',
149
+				'HeroSection',
150
+				'BodySection',
151
+				'SidebarSection',
152
+				'FooterSection',
153
+			],
154
+			'view_name'  => 'GenericTemplate',
155
+		],
156
+	],
157 157
 
158
-    /*
158
+	/*
159 159
      * The `Section` implementations that are provided.
160 160
      *
161 161
      * Each section also defines what view it intends to use for rendering.
162 162
      */
163
-    'sections'            => [
164
-        'HeaderSection'  => [
165
-            'css_class'  => 'header',
166
-            'class_name' => 'BrightNucleus\ChainMail\Section\GenericSection',
167
-            'view_name'  => 'GenericSection',
168
-        ],
169
-        'BodySection'    => [
170
-            'css_class'  => 'body',
171
-            'class_name' => 'BrightNucleus\ChainMail\Section\GenericSection',
172
-            'view_name'  => 'GenericSection',
173
-        ],
174
-        'FooterSection'  => [
175
-            'css_class'  => 'footer',
176
-            'class_name' => 'BrightNucleus\ChainMail\Section\GenericSection',
177
-            'view_name'  => 'GenericSection',
178
-        ],
179
-        'HeroSection'    => [
180
-            'css_class'  => 'hero',
181
-            'class_name' => 'BrightNucleus\ChainMail\Section\GenericSection',
182
-            'view_name'  => 'GenericSection',
183
-        ],
184
-        'SidebarSection' => [
185
-            'css_class'  => 'sidebar',
186
-            'class_name' => 'BrightNucleus\ChainMail\Section\GenericSection',
187
-            'view_name'  => 'GenericSection',
188
-        ],
189
-    ],
163
+	'sections'            => [
164
+		'HeaderSection'  => [
165
+			'css_class'  => 'header',
166
+			'class_name' => 'BrightNucleus\ChainMail\Section\GenericSection',
167
+			'view_name'  => 'GenericSection',
168
+		],
169
+		'BodySection'    => [
170
+			'css_class'  => 'body',
171
+			'class_name' => 'BrightNucleus\ChainMail\Section\GenericSection',
172
+			'view_name'  => 'GenericSection',
173
+		],
174
+		'FooterSection'  => [
175
+			'css_class'  => 'footer',
176
+			'class_name' => 'BrightNucleus\ChainMail\Section\GenericSection',
177
+			'view_name'  => 'GenericSection',
178
+		],
179
+		'HeroSection'    => [
180
+			'css_class'  => 'hero',
181
+			'class_name' => 'BrightNucleus\ChainMail\Section\GenericSection',
182
+			'view_name'  => 'GenericSection',
183
+		],
184
+		'SidebarSection' => [
185
+			'css_class'  => 'sidebar',
186
+			'class_name' => 'BrightNucleus\ChainMail\Section\GenericSection',
187
+			'view_name'  => 'GenericSection',
188
+		],
189
+	],
190 190
 ];
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@
 block discarded – undo
22 22
      * specific view to be rendered.
23 23
      */
24 24
     'view_root_locations' => [
25
-        'default' => realpath(__DIR__ . '/../views'),
25
+        'default' => realpath(__DIR__.'/../views'),
26 26
     ],
27 27
 
28 28
     /*
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 2 patches
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.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -155,6 +155,6 @@
 block discarded – undo
155 155
     protected function getViewName(array $context)
156 156
     {
157 157
         return $this->config['templates'][$this->getTemplateName()]['view_name']
158
-               . '.' . $context['format'];
158
+               . '.'.$context['format'];
159 159
     }
160 160
 }
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/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 3 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -155,7 +155,7 @@
 block discarded – undo
155 155
         if ( ! $template instanceof Template) {
156 156
             throw new InvalidTemplate(
157 157
                 'Could not set the template, invalid type.',
158
-                (array)$template
158
+                (array) $template
159 159
             );
160 160
         }
161 161
         $this->template = $template;
Please login to merge, or discard this patch.
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/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.
src/Template/AbstractTemplate.php 2 patches
Indentation   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -29,132 +29,132 @@
 block discarded – undo
29 29
 abstract class AbstractTemplate implements Template
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
-     * Name of the template.
43
-     *
44
-     * @since 1.0.0
45
-     *
46
-     * @var string
47
-     */
48
-    protected $templateName;
49
-
50
-    /**
51
-     * ViewBuilder to create template and section views.
52
-     *
53
-     * @since 1.0.0
54
-     *
55
-     * @var ViewBuilder
56
-     */
57
-    protected $viewBuilder;
58
-
59
-    /**
60
-     * Instantiate a AbstractTemplate object.
61
-     *
62
-     * @since 1.0.0
63
-     *
64
-     * @param ConfigInterface $config    Configuration settings.
65
-     * @param array           $arguments Arguments that are passed through the constructor.
66
-     *                                   Contained elements: string $template
67
-     *
68
-     * @throws RuntimeException
69
-     */
70
-    public function __construct($config, array $arguments)
71
-    {
72
-        $this->config = $config;
73
-        list($template, $this->viewBuilder) = $arguments;
74
-        $this->setTemplateName($template);
75
-    }
76
-
77
-    /**
78
-     * Get the name of the Template.
79
-     *
80
-     * @since 1.0.0
81
-     *
82
-     * @return string Name of the template.
83
-     */
84
-    public function getTemplateName()
85
-    {
86
-        return $this->templateName;
87
-    }
88
-
89
-    /**
90
-     * Set the name of the Template.
91
-     *
92
-     * @since 1.0.0
93
-     *
94
-     * @param string|null $template Optional. Name of the template.
95
-     *
96
-     * @throws FailedToInitialiseTemplate If no template name was passed.
97
-     * @throws FailedToInitialiseTemplate If an unknown template name was passed.
98
-     */
99
-    protected function setTemplateName($template = null)
100
-    {
101
-        if (null === $template) {
102
-            throw new FailedToInitialiseTemplate('Initialised template without passing it a template name.');
103
-        }
104
-        if ( ! array_key_exists($template, $this->config['templates'])) {
105
-            throw new FailedToInitialiseTemplate('Initialised template with an unknown template name.');
106
-        }
107
-        $this->templateName = $template;
108
-    }
109
-
110
-    /**
111
-     * Get an array of Sections that are used by this template.
112
-     *
113
-     * @since 1.0.0
114
-     *
115
-     * @return array Sections that are used by this template.
116
-     */
117
-    public function getUsedSections()
118
-    {
119
-        return $this->config['templates'][$this->getTemplateName()]['sections'];
120
-    }
121
-
122
-    /**
123
-     * Render the template for a given context.
124
-     *
125
-     * @since 1.0.0
126
-     *
127
-     * @param array $context The context in which to render the template.
128
-     *
129
-     * @return string The rendered content.
130
-     */
131
-    public function render(array $context)
132
-    {
133
-
134
-        $viewName = $this->getViewName($context);
135
-        $view     = $this->viewBuilder->create($viewName);
136
-
137
-        $sanitizerType    = $this->config['formats'][$context['format']]['sanitizer'];
138
-        $sanitizerFactory = new Factory($this->config, 'sanitizers');
139
-        $sanitizer        = $sanitizerFactory->create($sanitizerType);
140
-
141
-        $output = $view->render($context);
142
-
143
-        return $sanitizer->sanitize($output, $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 Context in which to get the view name.
152
-     *
153
-     * @return string Name of the view.
154
-     */
155
-    protected function getViewName(array $context)
156
-    {
157
-        return $this->config['templates'][$this->getTemplateName()]['view_name']
158
-               . '.' . $context['format'];
159
-    }
32
+	/**
33
+	 * Configuration Settings.
34
+	 *
35
+	 * @since 1.0.0
36
+	 *
37
+	 * @var ConfigInterface
38
+	 */
39
+	protected $config;
40
+
41
+	/**
42
+	 * Name of the template.
43
+	 *
44
+	 * @since 1.0.0
45
+	 *
46
+	 * @var string
47
+	 */
48
+	protected $templateName;
49
+
50
+	/**
51
+	 * ViewBuilder to create template and section views.
52
+	 *
53
+	 * @since 1.0.0
54
+	 *
55
+	 * @var ViewBuilder
56
+	 */
57
+	protected $viewBuilder;
58
+
59
+	/**
60
+	 * Instantiate a AbstractTemplate object.
61
+	 *
62
+	 * @since 1.0.0
63
+	 *
64
+	 * @param ConfigInterface $config    Configuration settings.
65
+	 * @param array           $arguments Arguments that are passed through the constructor.
66
+	 *                                   Contained elements: string $template
67
+	 *
68
+	 * @throws RuntimeException
69
+	 */
70
+	public function __construct($config, array $arguments)
71
+	{
72
+		$this->config = $config;
73
+		list($template, $this->viewBuilder) = $arguments;
74
+		$this->setTemplateName($template);
75
+	}
76
+
77
+	/**
78
+	 * Get the name of the Template.
79
+	 *
80
+	 * @since 1.0.0
81
+	 *
82
+	 * @return string Name of the template.
83
+	 */
84
+	public function getTemplateName()
85
+	{
86
+		return $this->templateName;
87
+	}
88
+
89
+	/**
90
+	 * Set the name of the Template.
91
+	 *
92
+	 * @since 1.0.0
93
+	 *
94
+	 * @param string|null $template Optional. Name of the template.
95
+	 *
96
+	 * @throws FailedToInitialiseTemplate If no template name was passed.
97
+	 * @throws FailedToInitialiseTemplate If an unknown template name was passed.
98
+	 */
99
+	protected function setTemplateName($template = null)
100
+	{
101
+		if (null === $template) {
102
+			throw new FailedToInitialiseTemplate('Initialised template without passing it a template name.');
103
+		}
104
+		if ( ! array_key_exists($template, $this->config['templates'])) {
105
+			throw new FailedToInitialiseTemplate('Initialised template with an unknown template name.');
106
+		}
107
+		$this->templateName = $template;
108
+	}
109
+
110
+	/**
111
+	 * Get an array of Sections that are used by this template.
112
+	 *
113
+	 * @since 1.0.0
114
+	 *
115
+	 * @return array Sections that are used by this template.
116
+	 */
117
+	public function getUsedSections()
118
+	{
119
+		return $this->config['templates'][$this->getTemplateName()]['sections'];
120
+	}
121
+
122
+	/**
123
+	 * Render the template for a given context.
124
+	 *
125
+	 * @since 1.0.0
126
+	 *
127
+	 * @param array $context The context in which to render the template.
128
+	 *
129
+	 * @return string The rendered content.
130
+	 */
131
+	public function render(array $context)
132
+	{
133
+
134
+		$viewName = $this->getViewName($context);
135
+		$view     = $this->viewBuilder->create($viewName);
136
+
137
+		$sanitizerType    = $this->config['formats'][$context['format']]['sanitizer'];
138
+		$sanitizerFactory = new Factory($this->config, 'sanitizers');
139
+		$sanitizer        = $sanitizerFactory->create($sanitizerType);
140
+
141
+		$output = $view->render($context);
142
+
143
+		return $sanitizer->sanitize($output, $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 Context in which to get the view name.
152
+	 *
153
+	 * @return string Name of the view.
154
+	 */
155
+	protected function getViewName(array $context)
156
+	{
157
+		return $this->config['templates'][$this->getTemplateName()]['view_name']
158
+			   . '.' . $context['format'];
159
+	}
160 160
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -155,6 +155,6 @@
 block discarded – undo
155 155
     protected function getViewName(array $context)
156 156
     {
157 157
         return $this->config['templates'][$this->getTemplateName()]['view_name']
158
-               . '.' . $context['format'];
158
+               . '.'.$context['format'];
159 159
     }
160 160
 }
Please login to merge, or discard this patch.