@@ -22,17 +22,17 @@ |
||
| 22 | 22 | class HTMLValidator extends AbstractValidator |
| 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 | - * @return string Validated content. |
|
| 33 | - */ |
|
| 34 | - public function validate($content, array $context) |
|
| 35 | - { |
|
| 36 | - return $content; |
|
| 37 | - } |
|
| 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 | + * @return string Validated content. |
|
| 33 | + */ |
|
| 34 | + public function validate($content, array $context) |
|
| 35 | + { |
|
| 36 | + return $content; |
|
| 37 | + } |
|
| 38 | 38 | } |
| 39 | 39 | \ No newline at end of file |
@@ -1,13 +1,13 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * TextValidator |
|
| 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 | + * TextValidator |
|
| 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\Validator; |
| 13 | 13 | |
@@ -22,17 +22,17 @@ discard block |
||
| 22 | 22 | class TextValidator extends AbstractValidator |
| 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 | - * @return string Validated content. |
|
| 33 | - */ |
|
| 34 | - public function validate($content, array $context) |
|
| 35 | - { |
|
| 36 | - return $content; |
|
| 37 | - } |
|
| 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 | + * @return string Validated content. |
|
| 33 | + */ |
|
| 34 | + public function validate($content, array $context) |
|
| 35 | + { |
|
| 36 | + return $content; |
|
| 37 | + } |
|
| 38 | 38 | } |
| 39 | 39 | \ No newline at end of file |
@@ -1,13 +1,13 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * ValidatorInterface |
|
| 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 | + * ValidatorInterface |
|
| 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,14 +22,14 @@ discard block |
||
| 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 | - * @return string Validated content. |
|
| 33 | - */ |
|
| 34 | - 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 | + * @return string Validated content. |
|
| 33 | + */ |
|
| 34 | + public function validate($content, array $context); |
|
| 35 | 35 | } |
| 36 | 36 | \ No newline at end of file |
@@ -1,13 +1,13 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * AbstractView |
|
| 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 | + * AbstractView |
|
| 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 | |
@@ -25,35 +25,35 @@ discard block |
||
| 25 | 25 | abstract class AbstractView implements ViewInterface |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Configuration Settings. |
|
| 30 | - * |
|
| 31 | - * @since 1.0.0 |
|
| 32 | - * |
|
| 33 | - * @var ConfigInterface |
|
| 34 | - */ |
|
| 35 | - protected $config; |
|
| 28 | + /** |
|
| 29 | + * Configuration Settings. |
|
| 30 | + * |
|
| 31 | + * @since 1.0.0 |
|
| 32 | + * |
|
| 33 | + * @var ConfigInterface |
|
| 34 | + */ |
|
| 35 | + protected $config; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Location of the view data. |
|
| 39 | - * |
|
| 40 | - * @since 1.0.0 |
|
| 41 | - * |
|
| 42 | - * @var 1.0.0 |
|
| 43 | - */ |
|
| 44 | - protected $viewLocation; |
|
| 37 | + /** |
|
| 38 | + * Location of the view data. |
|
| 39 | + * |
|
| 40 | + * @since 1.0.0 |
|
| 41 | + * |
|
| 42 | + * @var 1.0.0 |
|
| 43 | + */ |
|
| 44 | + protected $viewLocation; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Instantiate a View object. |
|
| 48 | - * |
|
| 49 | - * @since 1.0.0 |
|
| 50 | - * |
|
| 51 | - * @param ConfigInterface $config Configuration settings. |
|
| 52 | - * @param string $viewLocation Location of the View to render. |
|
| 53 | - */ |
|
| 54 | - public function __construct($config, $viewLocation) |
|
| 55 | - { |
|
| 56 | - $this->config = $config; |
|
| 57 | - $this->viewLocation = $viewLocation; |
|
| 58 | - } |
|
| 46 | + /** |
|
| 47 | + * Instantiate a View object. |
|
| 48 | + * |
|
| 49 | + * @since 1.0.0 |
|
| 50 | + * |
|
| 51 | + * @param ConfigInterface $config Configuration settings. |
|
| 52 | + * @param string $viewLocation Location of the View to render. |
|
| 53 | + */ |
|
| 54 | + public function __construct($config, $viewLocation) |
|
| 55 | + { |
|
| 56 | + $this->config = $config; |
|
| 57 | + $this->viewLocation = $viewLocation; |
|
| 58 | + } |
|
| 59 | 59 | } |
| 60 | 60 | \ No newline at end of file |
@@ -1,13 +1,13 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * ViewInterface |
|
| 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 | + * ViewInterface |
|
| 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 | |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | namespace BrightNucleus\ChainMail; |
| 13 | 13 | |
| 14 | 14 | if ( ! $content) { |
| 15 | - return; |
|
| 15 | + return; |
|
| 16 | 16 | } |
| 17 | 17 | ?> |
| 18 | 18 | <div class="<?php echo $context['css_class']; ?>"><?php echo $content; ?></div> |
@@ -1,13 +1,13 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * GenericSection Text View |
|
| 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 | + * GenericSection Text View |
|
| 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 | |
@@ -1,13 +1,13 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * AbstractMail |
|
| 4 | - * |
|
| 5 | - * @package brightnucleus/chainmail |
|
| 6 | - * @author Alain Schlesser <[email protected]> |
|
| 7 | - * @license GPL-2.0+ |
|
| 8 | - * @link http://www.brightnucleus.com/ |
|
| 9 | - * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
| 10 | - */ |
|
| 3 | + * AbstractMail |
|
| 4 | + * |
|
| 5 | + * @package brightnucleus/chainmail |
|
| 6 | + * @author Alain Schlesser <[email protected]> |
|
| 7 | + * @license GPL-2.0+ |
|
| 8 | + * @link http://www.brightnucleus.com/ |
|
| 9 | + * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
| 10 | + */ |
|
| 11 | 11 | |
| 12 | 12 | namespace BrightNucleus\ChainMail\Mail; |
| 13 | 13 | |
@@ -29,200 +29,200 @@ discard block |
||
| 29 | 29 | abstract class AbstractMail implements MailInterface |
| 30 | 30 | { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Configuration Settings. |
|
| 34 | - * |
|
| 35 | - * @since 1.0.0 |
|
| 36 | - * |
|
| 37 | - * @var ConfigInterface |
|
| 38 | - */ |
|
| 39 | - protected $config; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Template that is used for the email. |
|
| 43 | - * |
|
| 44 | - * @since 1.0.0 |
|
| 45 | - * |
|
| 46 | - * @var TemplateInterface |
|
| 47 | - */ |
|
| 48 | - protected $template; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Content for the different sections. |
|
| 52 | - * |
|
| 53 | - * @since 1.0.0 |
|
| 54 | - * |
|
| 55 | - * @var array |
|
| 56 | - */ |
|
| 57 | - protected $sectionContent = []; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Format of the mail. |
|
| 61 | - * |
|
| 62 | - * @since 1.0.0 |
|
| 63 | - * |
|
| 64 | - * @var string |
|
| 65 | - */ |
|
| 66 | - protected $format; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Instantiate an AbstractMail object. |
|
| 70 | - * |
|
| 71 | - * @since 1.0.0 |
|
| 72 | - * |
|
| 73 | - * @param ConfigInterface $config |
|
| 74 | - */ |
|
| 75 | - public function __construct(ConfigInterface $config) |
|
| 76 | - { |
|
| 77 | - $this->config = $config; |
|
| 78 | - $this->setFormat(); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Set the format of the mail. |
|
| 83 | - * |
|
| 84 | - * @since 1.0.0 |
|
| 85 | - * |
|
| 86 | - * @return string Format of the Mail. |
|
| 87 | - */ |
|
| 88 | - protected function getFormat() |
|
| 89 | - { |
|
| 90 | - return $this->format; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Set the format of the mail. |
|
| 95 | - * |
|
| 96 | - * @since 1.0.0 |
|
| 97 | - * |
|
| 98 | - * @return void |
|
| 99 | - */ |
|
| 100 | - abstract protected function setFormat(); |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Set the template to use for the renderer. |
|
| 104 | - * |
|
| 105 | - * @since 1.0.0 |
|
| 106 | - * |
|
| 107 | - * @param string|TemplateInterface $template Template to use for the |
|
| 108 | - * renderer. |
|
| 109 | - * @throws RuntimeException |
|
| 110 | - */ |
|
| 111 | - public function setTemplate($template) |
|
| 112 | - { |
|
| 113 | - if (is_string($template)) { |
|
| 114 | - $template = $this->createTemplate($template); |
|
| 115 | - } |
|
| 116 | - $this->template = $template; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Get the template to use for the renderer. |
|
| 121 | - * |
|
| 122 | - * @since 1.0.0 |
|
| 123 | - * |
|
| 124 | - * @return TemplateInterface Reference to the template that is used. |
|
| 125 | - * @throws RuntimeException |
|
| 126 | - */ |
|
| 127 | - public function getTemplate() |
|
| 128 | - { |
|
| 129 | - |
|
| 130 | - if ( ! $this->template) { |
|
| 131 | - $this->setDefaultTemplate(); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - if (is_string($this->template)) { |
|
| 135 | - $this->template = $this->createTemplate($this->template); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $this->template; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Set the template to the default template defined in the configuration. |
|
| 143 | - * |
|
| 144 | - * @since 1.0.0 |
|
| 145 | - * |
|
| 146 | - * @throws RuntimeException |
|
| 147 | - */ |
|
| 148 | - protected function setDefaultTemplate() |
|
| 149 | - { |
|
| 150 | - $defaultTemplate = $this->config->getKey('default_template'); |
|
| 151 | - $this->setTemplate($defaultTemplate); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Create an instance of a template. |
|
| 156 | - * |
|
| 157 | - * @since 1.0.0 |
|
| 158 | - * |
|
| 159 | - * @param string $template Template to instantiate. |
|
| 160 | - * @return TemplateInterface $template Newly created instance. |
|
| 161 | - * @throws RuntimeException |
|
| 162 | - */ |
|
| 163 | - protected function createTemplate($template) |
|
| 164 | - { |
|
| 165 | - $templateFactory = new Factory($this->config, 'templates'); |
|
| 166 | - |
|
| 167 | - return $templateFactory->create($template, [$template]); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Add a section to the Mail. |
|
| 172 | - * |
|
| 173 | - * @since 1.0.0 |
|
| 174 | - * |
|
| 175 | - * @param string $type Type of section to add. |
|
| 176 | - * @param string $content Content of the section. |
|
| 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 | - * @return string Rendered output of the email |
|
| 191 | - * @throws RuntimeException |
|
| 192 | - */ |
|
| 193 | - public function render(array $context) |
|
| 194 | - { |
|
| 195 | - |
|
| 196 | - $template = $this->getTemplate(); |
|
| 197 | - |
|
| 198 | - $context['template'] = $template; |
|
| 199 | - |
|
| 200 | - $sections = $template->getUsedSections(); |
|
| 201 | - |
|
| 202 | - $sectionFactory = new Factory($this->config, 'sections'); |
|
| 203 | - foreach ($sections as $section) { |
|
| 204 | - $content = null; |
|
| 205 | - if (array_key_exists($section, $this->sectionContent)) { |
|
| 206 | - $content = $this->sectionContent[$section]; |
|
| 207 | - } |
|
| 208 | - $context['sections'][$section] = $sectionFactory->create($section, |
|
| 209 | - [$section, $content]); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - $context['format'] = $this->getFormat(); |
|
| 213 | - |
|
| 214 | - $context = $this->setContext($context); |
|
| 215 | - |
|
| 216 | - return $template->render($context); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * Set the context of the mail. |
|
| 221 | - * |
|
| 222 | - * @since 1.0.0 |
|
| 223 | - * |
|
| 224 | - * @param array $context Context to set/modify. |
|
| 225 | - * @return array Updated context. |
|
| 226 | - */ |
|
| 227 | - abstract protected function setContext(array $context); |
|
| 32 | + /** |
|
| 33 | + * Configuration Settings. |
|
| 34 | + * |
|
| 35 | + * @since 1.0.0 |
|
| 36 | + * |
|
| 37 | + * @var ConfigInterface |
|
| 38 | + */ |
|
| 39 | + protected $config; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Template that is used for the email. |
|
| 43 | + * |
|
| 44 | + * @since 1.0.0 |
|
| 45 | + * |
|
| 46 | + * @var TemplateInterface |
|
| 47 | + */ |
|
| 48 | + protected $template; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Content for the different sections. |
|
| 52 | + * |
|
| 53 | + * @since 1.0.0 |
|
| 54 | + * |
|
| 55 | + * @var array |
|
| 56 | + */ |
|
| 57 | + protected $sectionContent = []; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Format of the mail. |
|
| 61 | + * |
|
| 62 | + * @since 1.0.0 |
|
| 63 | + * |
|
| 64 | + * @var string |
|
| 65 | + */ |
|
| 66 | + protected $format; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Instantiate an AbstractMail object. |
|
| 70 | + * |
|
| 71 | + * @since 1.0.0 |
|
| 72 | + * |
|
| 73 | + * @param ConfigInterface $config |
|
| 74 | + */ |
|
| 75 | + public function __construct(ConfigInterface $config) |
|
| 76 | + { |
|
| 77 | + $this->config = $config; |
|
| 78 | + $this->setFormat(); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Set the format of the mail. |
|
| 83 | + * |
|
| 84 | + * @since 1.0.0 |
|
| 85 | + * |
|
| 86 | + * @return string Format of the Mail. |
|
| 87 | + */ |
|
| 88 | + protected function getFormat() |
|
| 89 | + { |
|
| 90 | + return $this->format; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Set the format of the mail. |
|
| 95 | + * |
|
| 96 | + * @since 1.0.0 |
|
| 97 | + * |
|
| 98 | + * @return void |
|
| 99 | + */ |
|
| 100 | + abstract protected function setFormat(); |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Set the template to use for the renderer. |
|
| 104 | + * |
|
| 105 | + * @since 1.0.0 |
|
| 106 | + * |
|
| 107 | + * @param string|TemplateInterface $template Template to use for the |
|
| 108 | + * renderer. |
|
| 109 | + * @throws RuntimeException |
|
| 110 | + */ |
|
| 111 | + public function setTemplate($template) |
|
| 112 | + { |
|
| 113 | + if (is_string($template)) { |
|
| 114 | + $template = $this->createTemplate($template); |
|
| 115 | + } |
|
| 116 | + $this->template = $template; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Get the template to use for the renderer. |
|
| 121 | + * |
|
| 122 | + * @since 1.0.0 |
|
| 123 | + * |
|
| 124 | + * @return TemplateInterface Reference to the template that is used. |
|
| 125 | + * @throws RuntimeException |
|
| 126 | + */ |
|
| 127 | + public function getTemplate() |
|
| 128 | + { |
|
| 129 | + |
|
| 130 | + if ( ! $this->template) { |
|
| 131 | + $this->setDefaultTemplate(); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + if (is_string($this->template)) { |
|
| 135 | + $this->template = $this->createTemplate($this->template); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $this->template; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Set the template to the default template defined in the configuration. |
|
| 143 | + * |
|
| 144 | + * @since 1.0.0 |
|
| 145 | + * |
|
| 146 | + * @throws RuntimeException |
|
| 147 | + */ |
|
| 148 | + protected function setDefaultTemplate() |
|
| 149 | + { |
|
| 150 | + $defaultTemplate = $this->config->getKey('default_template'); |
|
| 151 | + $this->setTemplate($defaultTemplate); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Create an instance of a template. |
|
| 156 | + * |
|
| 157 | + * @since 1.0.0 |
|
| 158 | + * |
|
| 159 | + * @param string $template Template to instantiate. |
|
| 160 | + * @return TemplateInterface $template Newly created instance. |
|
| 161 | + * @throws RuntimeException |
|
| 162 | + */ |
|
| 163 | + protected function createTemplate($template) |
|
| 164 | + { |
|
| 165 | + $templateFactory = new Factory($this->config, 'templates'); |
|
| 166 | + |
|
| 167 | + return $templateFactory->create($template, [$template]); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Add a section to the Mail. |
|
| 172 | + * |
|
| 173 | + * @since 1.0.0 |
|
| 174 | + * |
|
| 175 | + * @param string $type Type of section to add. |
|
| 176 | + * @param string $content Content of the section. |
|
| 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 | + * @return string Rendered output of the email |
|
| 191 | + * @throws RuntimeException |
|
| 192 | + */ |
|
| 193 | + public function render(array $context) |
|
| 194 | + { |
|
| 195 | + |
|
| 196 | + $template = $this->getTemplate(); |
|
| 197 | + |
|
| 198 | + $context['template'] = $template; |
|
| 199 | + |
|
| 200 | + $sections = $template->getUsedSections(); |
|
| 201 | + |
|
| 202 | + $sectionFactory = new Factory($this->config, 'sections'); |
|
| 203 | + foreach ($sections as $section) { |
|
| 204 | + $content = null; |
|
| 205 | + if (array_key_exists($section, $this->sectionContent)) { |
|
| 206 | + $content = $this->sectionContent[$section]; |
|
| 207 | + } |
|
| 208 | + $context['sections'][$section] = $sectionFactory->create($section, |
|
| 209 | + [$section, $content]); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + $context['format'] = $this->getFormat(); |
|
| 213 | + |
|
| 214 | + $context = $this->setContext($context); |
|
| 215 | + |
|
| 216 | + return $template->render($context); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * Set the context of the mail. |
|
| 221 | + * |
|
| 222 | + * @since 1.0.0 |
|
| 223 | + * |
|
| 224 | + * @param array $context Context to set/modify. |
|
| 225 | + * @return array Updated context. |
|
| 226 | + */ |
|
| 227 | + abstract protected function setContext(array $context); |
|
| 228 | 228 | } |
@@ -1,13 +1,13 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * MailInterface |
|
| 4 | - * |
|
| 5 | - * @package brightnucleus/chainmail |
|
| 6 | - * @author Alain Schlesser <[email protected]> |
|
| 7 | - * @license GPL-2.0+ |
|
| 8 | - * @link http://www.brightnucleus.com/ |
|
| 9 | - * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
| 10 | - */ |
|
| 3 | + * MailInterface |
|
| 4 | + * |
|
| 5 | + * @package brightnucleus/chainmail |
|
| 6 | + * @author Alain Schlesser <[email protected]> |
|
| 7 | + * @license GPL-2.0+ |
|
| 8 | + * @link http://www.brightnucleus.com/ |
|
| 9 | + * @copyright 2016 Alain Schlesser, Bright Nucleus |
|
| 10 | + */ |
|
| 11 | 11 | |
| 12 | 12 | namespace BrightNucleus\ChainMail; |
| 13 | 13 | |
@@ -24,34 +24,34 @@ discard block |
||
| 24 | 24 | interface MailInterface extends Renderable |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Set the template that the email will use. |
|
| 29 | - * |
|
| 30 | - * @since 1.0.0 |
|
| 31 | - * |
|
| 32 | - * @param string|TemplateInterface $template Template to use. |
|
| 33 | - * @return void |
|
| 34 | - */ |
|
| 35 | - public function setTemplate($template); |
|
| 27 | + /** |
|
| 28 | + * Set the template that the email will use. |
|
| 29 | + * |
|
| 30 | + * @since 1.0.0 |
|
| 31 | + * |
|
| 32 | + * @param string|TemplateInterface $template Template to use. |
|
| 33 | + * @return void |
|
| 34 | + */ |
|
| 35 | + public function setTemplate($template); |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Get the instance of the template. |
|
| 39 | - * |
|
| 40 | - * @since 1.0.0 |
|
| 41 | - * |
|
| 42 | - * @return TemplateInterface |
|
| 43 | - */ |
|
| 44 | - public function getTemplate(); |
|
| 37 | + /** |
|
| 38 | + * Get the instance of the template. |
|
| 39 | + * |
|
| 40 | + * @since 1.0.0 |
|
| 41 | + * |
|
| 42 | + * @return TemplateInterface |
|
| 43 | + */ |
|
| 44 | + public function getTemplate(); |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Add a section to the Mail. |
|
| 48 | - * |
|
| 49 | - * @since 1.0.0 |
|
| 50 | - * |
|
| 51 | - * @param string $type Type of section to add. |
|
| 52 | - * @param string $content Content of the section. |
|
| 53 | - * @return void |
|
| 54 | - * @throws RuntimeException |
|
| 55 | - */ |
|
| 56 | - public function addSection($type, $content); |
|
| 46 | + /** |
|
| 47 | + * Add a section to the Mail. |
|
| 48 | + * |
|
| 49 | + * @since 1.0.0 |
|
| 50 | + * |
|
| 51 | + * @param string $type Type of section to add. |
|
| 52 | + * @param string $content Content of the section. |
|
| 53 | + * @return void |
|
| 54 | + * @throws RuntimeException |
|
| 55 | + */ |
|
| 56 | + public function addSection($type, $content); |
|
| 57 | 57 | } |