class_MailTemplateEngine.php
Go to the documentation of this file.00001 <?php
00024 class MailTemplateEngine extends BaseTemplateEngine implements CompileableTemplate {
00028 private $mainNodes = array("mail-data");
00029
00033 private $subNodes = array("subject-line", "sender-address", "recipient-address", "message");
00034
00038 private $mailerInstance = null;
00039
00043 private $currMainNode = "";
00044
00050 protected function __construct () {
00051
00052 parent::__construct(__CLASS__);
00053 }
00054
00069 public final static function createMailTemplateEngine ($basePath, ManageableLanguage $langInstance, FileIoHandler $ioInstance) {
00070
00071 $tplInstance = new MailTemplateEngine();
00072
00073
00074 if (empty($basePath)) {
00075
00076 throw new BasePathIsEmptyException($tplInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
00077 } elseif (!is_string($basePath)) {
00078
00079 throw new InvalidBasePathStringException(array($tplInstance, $basePath), self::EXCEPTION_INVALID_STRING);
00080 } elseif (!is_dir($basePath)) {
00081
00082 throw new BasePathIsNoDirectoryException(array($tplInstance, $basePath), self::EXCEPTION_INVALID_PATH_NAME);
00083 } elseif (!is_readable($basePath)) {
00084
00085 throw new BasePathReadProtectedException(array($tplInstance, $basePath), self::EXCEPTION_READ_PROTECED_PATH);
00086 }
00087
00088
00089 $cfgInstance = FrameworkConfiguration::getInstance();
00090
00091
00092 $tplInstance->setBasePath($basePath);
00093
00094
00095 $tplInstance->setLanguageInstance($langInstance);
00096 $tplInstance->setFileIoInstance($ioInstance);
00097
00098
00099 $tplInstance->setRawTemplateExtension($cfgInstance->readConfig('raw_template_extension'));
00100 $tplInstance->setCodeTemplateExtension($cfgInstance->readConfig('code_template_extension'));
00101
00102
00103 $tplInstance->setCompileOutputPath($cfgInstance->readConfig('base_path') . $cfgInstance->readConfig('compile_output_path'));
00104
00105
00106 return $tplInstance;
00107 }
00108
00114 public final function getCurrMainNode () {
00115 return $this->currMainNode;
00116 }
00117
00123 public final function getMainNodes () {
00124 return $this->mainNodes;
00125 }
00126
00132 public final function getSubNodes () {
00133 return $this->subNodes;
00134 }
00135
00145 protected function startElement ($resource, $element, array $attributes) {
00146
00147 $methodName = 'initEmail';
00148
00149
00150 $element = strtolower($element);
00151
00152
00153
00154 if (in_array($element, $this->getMainNodes())) {
00155
00156 $methodName = 'setEmail' . $this->convertToClassName($element);
00157 } elseif (in_array($element, $this->getSubNodes())) {
00158
00159 $methodName = 'setEmailProperty' . $this->convertToClassName($element);
00160 } elseif ($element != 'text-mail') {
00161
00162 throw new InvalidXmlNodeException(array($this, $element, $attributes), BaseHelper::EXCEPTION_XML_NODE_UNKNOWN);
00163 }
00164
00165
00166
00167 call_user_func_array(array($this, $methodName), $attributes);
00168 }
00169
00178 protected function endElement ($resource, $nodeName) {
00179
00180 $nodeName = strtolower($nodeName);
00181
00182
00183
00184 if (($nodeName != $this->getCurrMainNode()) && (in_array($nodeName, $this->getMainNodes()))) {
00185
00186 throw new XmlNodeMismatchException (array($this, $nodeName, $this->getCurrMainNode()), BaseHelper::EXCEPTION_XML_NODE_MISMATCH);
00187 } elseif (in_array($nodeName, $this->getSubNodes())) {
00188
00189 return;
00190 }
00191
00192
00193 $methodName = 'finish' . $this->convertToClassName($nodeName);
00194
00195
00196 call_user_func_array(array($this, $methodName), array());
00197 }
00198
00206 protected function characterHandler ($resource, $characters) {
00207
00208 $characters = trim($characters);
00209
00210
00211 if (empty($characters)) {
00212
00213 return false;
00214 }
00215
00216
00217 $this->assignVariable('message', $characters);
00218 }
00219
00226 private function initEmail () {
00227
00228 }
00229
00236 private function setEmailMailData () {
00237
00238 $this->currMainNode = 'mail-data';
00239 }
00240
00247 private function setEmailPropertySenderAddress ($senderAddress) {
00248
00249 $this->assignVariable('sender', $senderAddress);
00250 }
00251
00258 private function setEmailPropertyRecipientAddress ($recipientAddress) {
00259
00260 $this->assignVariable('recipient', $recipientAddress);
00261 }
00262
00269 private function setEmailPropertySubjectLine ($subjectLine) {
00270
00271 $this->assignVariable('subject', $subjectLine);
00272 }
00273
00279 private function setEmailPropertyMessage () {
00280
00281 }
00282
00289 private function finishMailData () {
00290
00291 $message = $this->readVariable('message');
00292 $this->setRawTemplateData($message);
00293
00294
00295
00296
00297
00298
00299 $this->compileVariables();
00300 }
00301
00307 private function finishTextMail () {
00308 $this->getMailerInstance()->invokeMailDelivery();
00309 }
00310
00317 public function getMailCacheFqfn () {
00318
00319 $fqfn = "";
00320 $this->debugBackTrace();
00321
00322
00323 return $fqfn;
00324 }
00325
00332 public final function setMailerInstance (DeliverableMail $mailerInstance) {
00333 $this->mailerInstance = $mailerInstance;
00334 }
00335
00341 protected final function getMailerInstance () {
00342 return $this->mailerInstance;
00343 }
00344
00351 public function transferToResponse (Responseable $responseInstance) {
00352 $responseInstance->writeToBody($this->getCompiledData());
00353 }
00354 }
00355
00356
00357 ?>