@@ -19,7 +19,7 @@ |
||
19 | 19 | * specific view to be rendered. |
20 | 20 | */ |
21 | 21 | 'view_root_locations' => [ |
22 | - 'default' => __DIR__ . '/../views', |
|
22 | + 'default' => __DIR__.'/../views', |
|
23 | 23 | ], |
24 | 24 | |
25 | 25 | /* |
@@ -13,187 +13,187 @@ |
||
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 |
@@ -150,7 +150,7 @@ |
||
150 | 150 | */ |
151 | 151 | protected function getViewLocation(array $context) |
152 | 152 | { |
153 | - return $this->getViewRoot() . '/sections/' . $context['format'] . '/' . $this->getViewName(); |
|
153 | + return $this->getViewRoot().'/sections/'.$context['format'].'/'.$this->getViewName(); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -1,13 +1,13 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * AbstractSection |
|
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 | + * AbstractSection |
|
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\Section; |
13 | 13 | |
@@ -27,156 +27,156 @@ discard block |
||
27 | 27 | abstract class AbstractSection implements SectionInterface |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * Name of the Section. |
|
32 | - * |
|
33 | - * @since 1.0.0 |
|
34 | - * |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - protected $sectionName; |
|
38 | - |
|
39 | - /** |
|
40 | - * Configuration Settings. |
|
41 | - * |
|
42 | - * @since 1.0.0 |
|
43 | - * |
|
44 | - * @var ConfigInterface |
|
45 | - */ |
|
46 | - protected $config; |
|
47 | - |
|
48 | - /** |
|
49 | - * Content of the section. |
|
50 | - * |
|
51 | - * @since 1.0.0 |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
55 | - protected $content; |
|
56 | - |
|
57 | - /** |
|
58 | - * Instantiate a AbstractSection object. |
|
59 | - * |
|
60 | - * @since 1.0.0 |
|
61 | - * |
|
62 | - * @param ConfigInterface $config Configuration settings. |
|
63 | - * @param array $arguments Arguments that are passed through |
|
64 | - * the constructor. Contained |
|
65 | - * elements: string $section, string |
|
66 | - * $content |
|
67 | - * @throws RuntimeException |
|
68 | - */ |
|
69 | - public function __construct($config, $arguments) |
|
70 | - { |
|
71 | - $this->config = $config; |
|
72 | - list($section, $content) = $arguments; |
|
73 | - $this->setSectionName($section); |
|
74 | - $this->content = $content; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Set the name of the Section. |
|
79 | - * |
|
80 | - * @since 1.0.0 |
|
81 | - * |
|
82 | - * @param string|null $section Optional. Name of the section. |
|
83 | - * @throws RuntimeException |
|
84 | - */ |
|
85 | - protected function setSectionName($section = null) |
|
86 | - { |
|
87 | - if (null === $section) { |
|
88 | - throw new RuntimeException('Initialised section without passing it a section name.'); |
|
89 | - } |
|
90 | - if ( ! array_key_exists($section, $this->config['sections'])) { |
|
91 | - throw new RuntimeException('Initialised section with an unknown section name.'); |
|
92 | - } |
|
93 | - $this->sectionName = $section; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Get the name of the Section. |
|
98 | - * |
|
99 | - * @since 1.0.0 |
|
100 | - * |
|
101 | - * @return string Name of the section. |
|
102 | - */ |
|
103 | - public function getSectionName() |
|
104 | - { |
|
105 | - return $this->sectionName; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Get the name of the View to use for rendering. |
|
110 | - * |
|
111 | - * @since 1.0.0 |
|
112 | - * |
|
113 | - * @return string Name of the view. |
|
114 | - */ |
|
115 | - protected function getViewName() |
|
116 | - { |
|
117 | - return $this->config['sections'][$this->getSectionName()]['view_name']; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Render the current Renderable for a given context. |
|
122 | - * |
|
123 | - * @since 1.0.0 |
|
124 | - * |
|
125 | - * @param array $context The context in which to render the Renderable. |
|
126 | - * @return string Rendered output of the Renderable. |
|
127 | - * @throws RuntimeException |
|
128 | - */ |
|
129 | - public function render(array $context) |
|
130 | - { |
|
131 | - |
|
132 | - $viewLocation = $this->getViewLocation($context); |
|
133 | - $viewType = $this->config['view_type']; |
|
134 | - |
|
135 | - $viewFactory = new Factory($this->config, 'view_types'); |
|
136 | - $view = $viewFactory->create($viewType, $viewLocation); |
|
137 | - |
|
138 | - $context['css_class'] = $this->getCSSClass(); |
|
139 | - |
|
140 | - return $view->render($context, $this->content); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Get the location of the view that is used for rendering. |
|
145 | - * |
|
146 | - * @since 1.0.0 |
|
147 | - * |
|
148 | - * @param array $context Context for which to get the view location. |
|
149 | - * @return string |
|
150 | - */ |
|
151 | - protected function getViewLocation(array $context) |
|
152 | - { |
|
153 | - return $this->getViewRoot() . '/sections/' . $context['format'] . '/' . $this->getViewName(); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Get the root location of the view that is used for rendering. |
|
158 | - * |
|
159 | - * @since 1.0.0 |
|
160 | - * |
|
161 | - * @return string |
|
162 | - */ |
|
163 | - protected function getViewRoot() |
|
164 | - { |
|
165 | - $viewRoots = $this->config['view_root_locations']; |
|
166 | - $viewRootKey = $this->config['sections'][$this->getSectionName()]['view_location']; |
|
167 | - |
|
168 | - return $viewRoots[$viewRootKey]; |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * Get the CSS class that is used for the section. |
|
173 | - * |
|
174 | - * @since 1.0.0 |
|
175 | - * |
|
176 | - * @return string |
|
177 | - */ |
|
178 | - protected function getCSSClass() |
|
179 | - { |
|
180 | - return $this->config['sections'][$this->getSectionName()]['css_class']; |
|
181 | - } |
|
30 | + /** |
|
31 | + * Name of the Section. |
|
32 | + * |
|
33 | + * @since 1.0.0 |
|
34 | + * |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + protected $sectionName; |
|
38 | + |
|
39 | + /** |
|
40 | + * Configuration Settings. |
|
41 | + * |
|
42 | + * @since 1.0.0 |
|
43 | + * |
|
44 | + * @var ConfigInterface |
|
45 | + */ |
|
46 | + protected $config; |
|
47 | + |
|
48 | + /** |
|
49 | + * Content of the section. |
|
50 | + * |
|
51 | + * @since 1.0.0 |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | + protected $content; |
|
56 | + |
|
57 | + /** |
|
58 | + * Instantiate a AbstractSection object. |
|
59 | + * |
|
60 | + * @since 1.0.0 |
|
61 | + * |
|
62 | + * @param ConfigInterface $config Configuration settings. |
|
63 | + * @param array $arguments Arguments that are passed through |
|
64 | + * the constructor. Contained |
|
65 | + * elements: string $section, string |
|
66 | + * $content |
|
67 | + * @throws RuntimeException |
|
68 | + */ |
|
69 | + public function __construct($config, $arguments) |
|
70 | + { |
|
71 | + $this->config = $config; |
|
72 | + list($section, $content) = $arguments; |
|
73 | + $this->setSectionName($section); |
|
74 | + $this->content = $content; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Set the name of the Section. |
|
79 | + * |
|
80 | + * @since 1.0.0 |
|
81 | + * |
|
82 | + * @param string|null $section Optional. Name of the section. |
|
83 | + * @throws RuntimeException |
|
84 | + */ |
|
85 | + protected function setSectionName($section = null) |
|
86 | + { |
|
87 | + if (null === $section) { |
|
88 | + throw new RuntimeException('Initialised section without passing it a section name.'); |
|
89 | + } |
|
90 | + if ( ! array_key_exists($section, $this->config['sections'])) { |
|
91 | + throw new RuntimeException('Initialised section with an unknown section name.'); |
|
92 | + } |
|
93 | + $this->sectionName = $section; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Get the name of the Section. |
|
98 | + * |
|
99 | + * @since 1.0.0 |
|
100 | + * |
|
101 | + * @return string Name of the section. |
|
102 | + */ |
|
103 | + public function getSectionName() |
|
104 | + { |
|
105 | + return $this->sectionName; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Get the name of the View to use for rendering. |
|
110 | + * |
|
111 | + * @since 1.0.0 |
|
112 | + * |
|
113 | + * @return string Name of the view. |
|
114 | + */ |
|
115 | + protected function getViewName() |
|
116 | + { |
|
117 | + return $this->config['sections'][$this->getSectionName()]['view_name']; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Render the current Renderable for a given context. |
|
122 | + * |
|
123 | + * @since 1.0.0 |
|
124 | + * |
|
125 | + * @param array $context The context in which to render the Renderable. |
|
126 | + * @return string Rendered output of the Renderable. |
|
127 | + * @throws RuntimeException |
|
128 | + */ |
|
129 | + public function render(array $context) |
|
130 | + { |
|
131 | + |
|
132 | + $viewLocation = $this->getViewLocation($context); |
|
133 | + $viewType = $this->config['view_type']; |
|
134 | + |
|
135 | + $viewFactory = new Factory($this->config, 'view_types'); |
|
136 | + $view = $viewFactory->create($viewType, $viewLocation); |
|
137 | + |
|
138 | + $context['css_class'] = $this->getCSSClass(); |
|
139 | + |
|
140 | + return $view->render($context, $this->content); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Get the location of the view that is used for rendering. |
|
145 | + * |
|
146 | + * @since 1.0.0 |
|
147 | + * |
|
148 | + * @param array $context Context for which to get the view location. |
|
149 | + * @return string |
|
150 | + */ |
|
151 | + protected function getViewLocation(array $context) |
|
152 | + { |
|
153 | + return $this->getViewRoot() . '/sections/' . $context['format'] . '/' . $this->getViewName(); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Get the root location of the view that is used for rendering. |
|
158 | + * |
|
159 | + * @since 1.0.0 |
|
160 | + * |
|
161 | + * @return string |
|
162 | + */ |
|
163 | + protected function getViewRoot() |
|
164 | + { |
|
165 | + $viewRoots = $this->config['view_root_locations']; |
|
166 | + $viewRootKey = $this->config['sections'][$this->getSectionName()]['view_location']; |
|
167 | + |
|
168 | + return $viewRoots[$viewRootKey]; |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * Get the CSS class that is used for the section. |
|
173 | + * |
|
174 | + * @since 1.0.0 |
|
175 | + * |
|
176 | + * @return string |
|
177 | + */ |
|
178 | + protected function getCSSClass() |
|
179 | + { |
|
180 | + return $this->config['sections'][$this->getSectionName()]['css_class']; |
|
181 | + } |
|
182 | 182 | } |
@@ -155,7 +155,7 @@ |
||
155 | 155 | */ |
156 | 156 | protected function getViewLocation(array $context) |
157 | 157 | { |
158 | - return $this->getViewRoot() . '/templates/' . $context['format'] . '/' . $this->getViewName(); |
|
158 | + return $this->getViewRoot().'/templates/'.$context['format'].'/'.$this->getViewName(); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -1,13 +1,13 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * AbstractTemplate |
|
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 | + * AbstractTemplate |
|
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\Template; |
13 | 13 | |
@@ -27,149 +27,149 @@ discard block |
||
27 | 27 | abstract class AbstractTemplate implements TemplateInterface |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * Configuration Settings. |
|
32 | - * |
|
33 | - * @since 1.0.0 |
|
34 | - * |
|
35 | - * @var ConfigInterface |
|
36 | - */ |
|
37 | - protected $config; |
|
38 | - |
|
39 | - /** |
|
40 | - * Name of the template. |
|
41 | - * |
|
42 | - * @since 1.0.0 |
|
43 | - * |
|
44 | - * @var string |
|
45 | - */ |
|
46 | - protected $templateName; |
|
47 | - |
|
48 | - /** |
|
49 | - * Instantiate a AbstractTemplate object. |
|
50 | - * |
|
51 | - * @since 1.0.0 |
|
52 | - * |
|
53 | - * @param ConfigInterface $config Configuration settings. |
|
54 | - * @param array $arguments Arguments that are passed through |
|
55 | - * the constructor. Contained |
|
56 | - * elements: string $template |
|
57 | - * @throws RuntimeException |
|
58 | - */ |
|
59 | - public function __construct($config, $arguments) |
|
60 | - { |
|
61 | - $this->config = $config; |
|
62 | - list($template) = $arguments; |
|
63 | - $this->setTemplateName($template); |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Get the name of the Template. |
|
68 | - * |
|
69 | - * @since 1.0.0 |
|
70 | - * |
|
71 | - * @return string Name of the template. |
|
72 | - */ |
|
73 | - public function getTemplateName() |
|
74 | - { |
|
75 | - return $this->templateName; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Set the name of the Template. |
|
80 | - * |
|
81 | - * @since 1.0.0 |
|
82 | - * |
|
83 | - * @param string|null $template Optional. Name of the template. |
|
84 | - * @throws RuntimeException |
|
85 | - */ |
|
86 | - protected function setTemplateName($template = null) |
|
87 | - { |
|
88 | - if (null === $template) { |
|
89 | - throw new RuntimeException('Initialised template without passing it a template name.'); |
|
90 | - } |
|
91 | - if ( ! array_key_exists($template, $this->config['templates'])) { |
|
92 | - throw new RuntimeException('Initialised template with an unknown template name.'); |
|
93 | - } |
|
94 | - $this->templateName = $template; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Get the name of the View to use for rendering. |
|
99 | - * |
|
100 | - * @since 1.0.0 |
|
101 | - * |
|
102 | - * @return string Name of the view. |
|
103 | - */ |
|
104 | - protected function getViewName() |
|
105 | - { |
|
106 | - return $this->config['templates'][$this->getTemplateName()]['view_name']; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Get an array of Sections that are used by this template. |
|
111 | - * |
|
112 | - * @since 1.0.0 |
|
113 | - * |
|
114 | - * @return array Sections that are used by this template. |
|
115 | - */ |
|
116 | - public function getUsedSections() |
|
117 | - { |
|
118 | - return $this->config['templates'][$this->getTemplateName()]['sections']; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Render the template for a given context. |
|
123 | - * |
|
124 | - * @since 1.0.0 |
|
125 | - * |
|
126 | - * @param array $context The context in which to render the template. |
|
127 | - * @return string The rendered content. |
|
128 | - * @throws RuntimeException |
|
129 | - */ |
|
130 | - public function render(array $context) |
|
131 | - { |
|
132 | - |
|
133 | - $viewLocation = $this->getViewLocation($context); |
|
134 | - $viewType = $this->config['view_type']; |
|
135 | - |
|
136 | - $viewFactory = new Factory($this->config, 'view_types'); |
|
137 | - $view = $viewFactory->create($viewType, $viewLocation); |
|
138 | - |
|
139 | - $sanitizerType = $this->config['formats'][$context['format']]['sanitizer']; |
|
140 | - $sanitizerFactory = new Factory($this->config, 'sanitizers'); |
|
141 | - $sanitizer = $sanitizerFactory->create($sanitizerType); |
|
142 | - |
|
143 | - $output = $view->render($context); |
|
144 | - |
|
145 | - return $sanitizer->sanitize($output, $context); |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Get the location of the view that is used for rendering. |
|
150 | - * |
|
151 | - * @since 1.0.0 |
|
152 | - * |
|
153 | - * @param array $context Context for which to get the view location. |
|
154 | - * @return string |
|
155 | - */ |
|
156 | - protected function getViewLocation(array $context) |
|
157 | - { |
|
158 | - return $this->getViewRoot() . '/templates/' . $context['format'] . '/' . $this->getViewName(); |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * Get the root location of the view that is used for rendering. |
|
163 | - * |
|
164 | - * @since 1.0.0 |
|
165 | - * |
|
166 | - * @return string |
|
167 | - */ |
|
168 | - protected function getViewRoot() |
|
169 | - { |
|
170 | - $viewRoots = $this->config['view_root_locations']; |
|
171 | - $viewRootKey = $this->config['templates'][$this->getTemplateName()]['view_location']; |
|
172 | - |
|
173 | - return $viewRoots[$viewRootKey]; |
|
174 | - } |
|
30 | + /** |
|
31 | + * Configuration Settings. |
|
32 | + * |
|
33 | + * @since 1.0.0 |
|
34 | + * |
|
35 | + * @var ConfigInterface |
|
36 | + */ |
|
37 | + protected $config; |
|
38 | + |
|
39 | + /** |
|
40 | + * Name of the template. |
|
41 | + * |
|
42 | + * @since 1.0.0 |
|
43 | + * |
|
44 | + * @var string |
|
45 | + */ |
|
46 | + protected $templateName; |
|
47 | + |
|
48 | + /** |
|
49 | + * Instantiate a AbstractTemplate object. |
|
50 | + * |
|
51 | + * @since 1.0.0 |
|
52 | + * |
|
53 | + * @param ConfigInterface $config Configuration settings. |
|
54 | + * @param array $arguments Arguments that are passed through |
|
55 | + * the constructor. Contained |
|
56 | + * elements: string $template |
|
57 | + * @throws RuntimeException |
|
58 | + */ |
|
59 | + public function __construct($config, $arguments) |
|
60 | + { |
|
61 | + $this->config = $config; |
|
62 | + list($template) = $arguments; |
|
63 | + $this->setTemplateName($template); |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Get the name of the Template. |
|
68 | + * |
|
69 | + * @since 1.0.0 |
|
70 | + * |
|
71 | + * @return string Name of the template. |
|
72 | + */ |
|
73 | + public function getTemplateName() |
|
74 | + { |
|
75 | + return $this->templateName; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Set the name of the Template. |
|
80 | + * |
|
81 | + * @since 1.0.0 |
|
82 | + * |
|
83 | + * @param string|null $template Optional. Name of the template. |
|
84 | + * @throws RuntimeException |
|
85 | + */ |
|
86 | + protected function setTemplateName($template = null) |
|
87 | + { |
|
88 | + if (null === $template) { |
|
89 | + throw new RuntimeException('Initialised template without passing it a template name.'); |
|
90 | + } |
|
91 | + if ( ! array_key_exists($template, $this->config['templates'])) { |
|
92 | + throw new RuntimeException('Initialised template with an unknown template name.'); |
|
93 | + } |
|
94 | + $this->templateName = $template; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Get the name of the View to use for rendering. |
|
99 | + * |
|
100 | + * @since 1.0.0 |
|
101 | + * |
|
102 | + * @return string Name of the view. |
|
103 | + */ |
|
104 | + protected function getViewName() |
|
105 | + { |
|
106 | + return $this->config['templates'][$this->getTemplateName()]['view_name']; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Get an array of Sections that are used by this template. |
|
111 | + * |
|
112 | + * @since 1.0.0 |
|
113 | + * |
|
114 | + * @return array Sections that are used by this template. |
|
115 | + */ |
|
116 | + public function getUsedSections() |
|
117 | + { |
|
118 | + return $this->config['templates'][$this->getTemplateName()]['sections']; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Render the template for a given context. |
|
123 | + * |
|
124 | + * @since 1.0.0 |
|
125 | + * |
|
126 | + * @param array $context The context in which to render the template. |
|
127 | + * @return string The rendered content. |
|
128 | + * @throws RuntimeException |
|
129 | + */ |
|
130 | + public function render(array $context) |
|
131 | + { |
|
132 | + |
|
133 | + $viewLocation = $this->getViewLocation($context); |
|
134 | + $viewType = $this->config['view_type']; |
|
135 | + |
|
136 | + $viewFactory = new Factory($this->config, 'view_types'); |
|
137 | + $view = $viewFactory->create($viewType, $viewLocation); |
|
138 | + |
|
139 | + $sanitizerType = $this->config['formats'][$context['format']]['sanitizer']; |
|
140 | + $sanitizerFactory = new Factory($this->config, 'sanitizers'); |
|
141 | + $sanitizer = $sanitizerFactory->create($sanitizerType); |
|
142 | + |
|
143 | + $output = $view->render($context); |
|
144 | + |
|
145 | + return $sanitizer->sanitize($output, $context); |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Get the location of the view that is used for rendering. |
|
150 | + * |
|
151 | + * @since 1.0.0 |
|
152 | + * |
|
153 | + * @param array $context Context for which to get the view location. |
|
154 | + * @return string |
|
155 | + */ |
|
156 | + protected function getViewLocation(array $context) |
|
157 | + { |
|
158 | + return $this->getViewRoot() . '/templates/' . $context['format'] . '/' . $this->getViewName(); |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * Get the root location of the view that is used for rendering. |
|
163 | + * |
|
164 | + * @since 1.0.0 |
|
165 | + * |
|
166 | + * @return string |
|
167 | + */ |
|
168 | + protected function getViewRoot() |
|
169 | + { |
|
170 | + $viewRoots = $this->config['view_root_locations']; |
|
171 | + $viewRootKey = $this->config['templates'][$this->getTemplateName()]['view_location']; |
|
172 | + |
|
173 | + return $viewRoots[$viewRootKey]; |
|
174 | + } |
|
175 | 175 | } |
@@ -37,7 +37,7 @@ |
||
37 | 37 | |
38 | 38 | ob_start(); |
39 | 39 | |
40 | - include $this->viewLocation . '.php'; |
|
40 | + include $this->viewLocation.'.php'; |
|
41 | 41 | |
42 | 42 | return ob_get_clean(); |
43 | 43 | } |
@@ -30,7 +30,7 @@ |
||
30 | 30 | * @param array $context The context in which to render the Renderable. |
31 | 31 | * @param string $content Optional. The content that the view should |
32 | 32 | * represent. |
33 | - * @return string|null Rendered output of the Renderable. |
|
33 | + * @return string Rendered output of the Renderable. |
|
34 | 34 | */ |
35 | 35 | public function render(array $context, $content = null) |
36 | 36 | { |
@@ -1,13 +1,13 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * PHPView |
|
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 | + * PHPView |
|
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\View; |
13 | 13 | |
@@ -22,23 +22,23 @@ discard block |
||
22 | 22 | class PHPView extends AbstractView |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Render the current Renderable for a given context. |
|
27 | - * |
|
28 | - * @since 1.0.0 |
|
29 | - * |
|
30 | - * @param array $context The context in which to render the Renderable. |
|
31 | - * @param string $content Optional. The content that the view should |
|
32 | - * represent. |
|
33 | - * @return string|null Rendered output of the Renderable. |
|
34 | - */ |
|
35 | - public function render(array $context, $content = null) |
|
36 | - { |
|
25 | + /** |
|
26 | + * Render the current Renderable for a given context. |
|
27 | + * |
|
28 | + * @since 1.0.0 |
|
29 | + * |
|
30 | + * @param array $context The context in which to render the Renderable. |
|
31 | + * @param string $content Optional. The content that the view should |
|
32 | + * represent. |
|
33 | + * @return string|null Rendered output of the Renderable. |
|
34 | + */ |
|
35 | + public function render(array $context, $content = null) |
|
36 | + { |
|
37 | 37 | |
38 | - ob_start(); |
|
38 | + ob_start(); |
|
39 | 39 | |
40 | - include $this->viewLocation . '.php'; |
|
40 | + include $this->viewLocation . '.php'; |
|
41 | 41 | |
42 | - return ob_get_clean(); |
|
43 | - } |
|
42 | + return ob_get_clean(); |
|
43 | + } |
|
44 | 44 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | class ChainMail |
28 | 28 | { |
29 | 29 | |
30 | - const DEFAULT_CONFIG = __DIR__ . '/../config/defaults.php'; |
|
30 | + const DEFAULT_CONFIG = __DIR__.'/../config/defaults.php'; |
|
31 | 31 | |
32 | 32 | /** |
33 | 33 | * Configuration Settings. |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | } |
58 | 58 | |
59 | 59 | $this->config = new Config(array_merge( |
60 | - (array)$defaults, |
|
61 | - (array)$config) |
|
60 | + (array) $defaults, |
|
61 | + (array) $config) |
|
62 | 62 | ); |
63 | 63 | } |
64 | 64 |
@@ -1,13 +1,13 @@ discard block |
||
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 |
||
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(self::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 (self::getUsedSections($context) as $section) { |
|
133 | - $output .= self::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(self::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 (self::getUsedSections($context) as $section) { |
|
133 | + $output .= self::renderSection($section, $context); |
|
134 | + } |
|
135 | + |
|
136 | + return $output; |
|
137 | + } |
|
138 | 138 | } |
@@ -1,13 +1,13 @@ discard block |
||
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 |
||
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 |
@@ -1,13 +1,13 @@ discard block |
||
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 |
||
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 |
@@ -1,13 +1,13 @@ discard block |
||
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 |
||
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 |
@@ -1,13 +1,13 @@ |
||
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 |