3 namespace Org\Mxchange\CoreFramework\Mailer\Debug;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
7 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
8 use Org\Mxchange\CoreFramework\Mailer\BaseMailer;
9 use Org\Mxchange\CoreFramework\Mailer\DeliverableMail;
10 use Org\Mxchange\CoreFramework\Manager\Login\ManageableMember;
11 use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
12 use Org\Mxchange\CoreFramework\Registry\Registry;
13 use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
16 * A mailer class for debugging purposes only. This class will print the
17 * prepared mail out and will not send it to the recipient.
19 * @author Roland Haeder <webmaster@shipsimu.org>
21 <<<<<<< HEAD:framework/main/classes/mailer/debug/class_DebugMailer.php
22 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
24 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team
25 >>>>>>> Some updates::inc/main/classes/mailer/debug/class_DebugMailer.php
26 * @license GNU GPL 3.0 or any newer version
27 * @link http://www.shipsimu.org
29 * This program is free software: you can redistribute it and/or modify
30 * it under the terms of the GNU General Public License as published by
31 * the Free Software Foundation, either version 3 of the License, or
32 * (at your option) any later version.
34 * This program is distributed in the hope that it will be useful,
35 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 * GNU General Public License for more details.
39 * You should have received a copy of the GNU General Public License
40 * along with this program. If not, see <http://www.gnu.org/licenses/>.
42 class DebugMailer extends BaseMailer implements DeliverableMail {
44 * Protected constructor
48 protected function __construct () {
49 // Call parent constructor
50 parent::__construct(__CLASS__);
54 * Creates an instance of this mailer class
56 * @param $templateInstance A template instance
57 * @param $applicationInstance An application helper class
58 * @param $templateName Name of email template to set
59 * @return $mailerInstance An instance of this mailer class
61 public static final function createDebugMailer (CompileableTemplate $templateInstance, ManageableApplication $applicationInstance, $templateName) {
63 $mailerInstance = new DebugMailer();
65 // Set template instance
66 $mailerInstance->setTemplateInstance($templateInstance);
68 // Set application instance
69 $mailerInstance->setApplicationInstance($applicationInstance);
72 $mailerInstance->setTemplateName($templateName);
74 // Return the instance
75 return $mailerInstance;
79 * Deliver email to the recipient(s)
82 * @throws InvalidInterfaceException If the recipient instance does not implement ManageableMember
84 public function deliverEmail () {
85 // Get template instance
86 $templateInstance = $this->getTemplateInstance();
88 // "Deliver" all emails
89 foreach ($this->getRecipientList() as $templateName => $recipientList) {
90 // Walk through all recipients and "sent", or better print, it out
91 foreach ($recipientList['recipients'] as $recipientInstance) {
92 // The recipient should be a user instance, right?
93 if (!$recipientInstance instanceof ManageableMember) {
94 // Invalid entry found!
95 throw new InvalidInterfaceException(array($this, 'ManageableMember'), self::EXCEPTION_REQUIRED_INTERFACE_MISSING);
98 // User class found, so entry is valid, first load the template
99 $this->loadTemplate($templateName);
102 $templateInstance->assignVariable('subject', $this->getSubjectLine());
104 // Walk through all variables, first config to assign them
105 foreach ($recipientList['config_vars'] as $variable => $dummy) {
106 // Load the config value and set it
107 $templateInstance->assignConfigVariable($variable);
110 // Now do the same with the values but ask the "value instance" instead!
111 foreach ($recipientList['value_vars'] as $variable => $dummy) {
112 // Is the value instance there?
113 if (!isset($recipientList['values'][$variable])) {
115 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
118 // Get the field from the value instance
119 $fieldValue = $recipientList['values'][$variable]->getField($variable);
121 // Set it in template engine
122 $templateInstance->assignVariable($variable, $fieldValue);
125 // Render the content
126 $templateInstance->renderXmlContent();
128 // Get responce instance
129 $responseInstance = FrameworkBootstrap::getResponseInstance();
131 // Transfer the data to the response
132 $templateInstance->transferToResponse($responseInstance);
138 * Send notification to the admin
143 public function sendAdminNotification () {
148 * Invokes the mail delivery process which will prepare the output of the message in a code template
152 public function invokeMailDelivery () {
153 // Get template instance
154 $templateInstance = $this->getTemplateInstance();
156 // Get the compiled message and set it as new template variable
157 $message = $templateInstance->getCompiledData();
158 $templateInstance->assignVariable('message', $message);
160 // Load the code template
161 $templateInstance->loadCodeTemplate('mail_debug');
163 // Compile the template
164 $templateInstance->compileTemplate();
166 // Assign this template with variable
167 $templateInstance->assignTemplateWithVariable('mail_debug', 'main_content');
169 // Load header template
170 $templateInstance->loadCodeTemplate('header');
172 // Compile and assign it with a variable
173 $templateInstance->compileTemplate();
174 $templateInstance->assignTemplateWithVariable('header', 'header');
176 // Load footer template
177 $templateInstance->loadCodeTemplate('footer');
179 // Compile and assign it with a variable
180 $templateInstance->compileTemplate();
181 $templateInstance->assignTemplateWithVariable('footer', 'footer');
183 // Load the master template
184 $templateInstance->loadCodeTemplate(Registry::getRegistry()->getInstance('app')->buildMasterTemplateName());
186 // Then compile it again
187 $templateInstance->compileVariables();