]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/template/mail/class_MailTemplateEngine.php
Continued:
[core.git] / framework / main / classes / template / mail / class_MailTemplateEngine.php
index 436b39b2ce84ccef52bb98d15373967f6082aee5..a54f98d9cbc28c947e57bf7ebe766cdb23f8561d 100644 (file)
@@ -3,13 +3,16 @@
 namespace Org\Mxchange\CoreFramework\Template\Engine;
 
 // Import framework stuff
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
 use Org\Mxchange\CoreFramework\Filesystem\InvalidDirectoryException;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
+use Org\Mxchange\CoreFramework\Helper\Application\ApplicationHelper;
 use Org\Mxchange\CoreFramework\Mailer\DeliverableMail;
-use Org\Mxchange\CoreFramework\Parser\Xml\XmlParser;
-use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
+use Org\Mxchange\CoreFramework\Parser\Parseable;
 use Org\Mxchange\CoreFramework\Response\Responseable;
 use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
 use Org\Mxchange\CoreFramework\Template\Engine\BaseTemplateEngine;
+use Org\Mxchange\CoreFramework\Utils\Strings\StringUtils;
 
 // Import SPL stuff
 use \UnexpectedValueException;
@@ -19,7 +22,7 @@ use \UnexpectedValueException;
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.shipsimu.org
  * @todo               This template engine does not make use of setTemplateType()
@@ -41,19 +44,19 @@ class MailTemplateEngine extends BaseTemplateEngine implements CompileableTempla
        /**
         * Main nodes in the XML tree
         */
-       private $mainNodes = array(
+       private $mainNodes = [
                'mail-data'
-       );
+       ];
 
        /**
         * Sub nodes in the XML tree
         */
-       private $subNodes = array(
+       private $subNodes = [
                'subject-line',
                'sender-address',
                'recipient-address',
                'message'
-       );
+       ];
 
        /**
         * Mailer instance
@@ -70,9 +73,12 @@ class MailTemplateEngine extends BaseTemplateEngine implements CompileableTempla
         *
         * @return      void
         */
-       protected function __construct () {
+       private function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
+
+               // Set template type
+               $this->setTemplateType('mail');
        }
 
        /**
@@ -90,18 +96,15 @@ class MailTemplateEngine extends BaseTemplateEngine implements CompileableTempla
                $templateInstance = new MailTemplateEngine();
 
                // Get the application instance from registry
-               $applicationInstance = GenericRegistry::getRegistry()->getInstance('application');
+               $applicationInstance = ApplicationHelper::getSelfInstance();
 
                // Determine base path
-               $templateBasePath = $templateInstance->getConfigInstance()->getConfigEntry('application_base_path') . $applicationInstance->getAppShortName(). '/';
+               $templateBasePath = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('application_base_path') . $applicationInstance->getAppShortName(). '/';
 
                // Is the base path valid?
                if (empty($templateBasePath)) {
                        // Base path is empty
-                       throw new UnexpectedValueException(sprintf('[%s:%d] Variable templateBasePath is empty.', $templateInstance->__toString(), __LINE__), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
-               } elseif (!is_string($templateBasePath)) {
-                       // Is not a string
-                       throw new UnexpectedValueException(sprintf('[%s:%d] %s is not a string with a base path.', $templateInstance->__toString(), __LINE__, $templateBasePath), self::EXCEPTION_INVALID_STRING);
+                       throw new UnexpectedValueException(sprintf('[%s:%d] Variable templateBasePath is empty.', $templateInstance->__toString(), __LINE__), FrameworkInterface::EXCEPTION_UNEXPECTED_VALUE);
                } elseif (!is_dir($templateBasePath)) {
                        // Is not a path
                        throw new InvalidDirectoryException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME);
@@ -114,13 +117,13 @@ class MailTemplateEngine extends BaseTemplateEngine implements CompileableTempla
                $templateInstance->setTemplateBasePath($templateBasePath);
 
                // Set template extensions
-               $templateInstance->setRawTemplateExtension($templateInstance->getConfigInstance()->getConfigEntry('raw_template_extension'));
-               $templateInstance->setCodeTemplateExtension($templateInstance->getConfigInstance()->getConfigEntry('code_template_extension'));
+               $templateInstance->setRawTemplateExtension(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('raw_template_extension'));
+               $templateInstance->setCodeTemplateExtension(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('code_template_extension'));
 
                // Absolute output path for compiled templates
                $templateInstance->setCompileOutputPath(sprintf('%s%s/',
                        $templateBasePath,
-                       $templateInstance->getConfigInstance()->getConfigEntry('compile_output_path')
+                       FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('compile_output_path')
                ));
 
                // Return the prepared instance
@@ -163,7 +166,7 @@ class MailTemplateEngine extends BaseTemplateEngine implements CompileableTempla
         * @return      void
         * @throws      InvalidXmlNodeException         If an unknown/invalid XML node name was found
         */
-       public function startElement ($resource, $element, array $attributes) {
+       public function startElement ($resource, string $element, array $attributes) {
                // Initial method name which will never be called...
                $methodName = 'initEmail';
 
@@ -174,13 +177,13 @@ class MailTemplateEngine extends BaseTemplateEngine implements CompileableTempla
                //* DEBUG: */ echo "START: &gt;".$element."&lt;<br />\n";
                if (in_array($element, $this->getMainNodes())) {
                        // Okay, main node found!
-                       $methodName = 'setEmail' . self::convertToClassName($element);
+                       $methodName = 'setEmail' . StringUtils::convertToClassName($element);
                } elseif (in_array($element, $this->getSubNodes())) {
                        // Sub node found
-                       $methodName = 'setEmailProperty' . self::convertToClassName($element);
+                       $methodName = 'setEmailProperty' . StringUtils::convertToClassName($element);
                } elseif ($element != 'text-mail') {
                        // Invalid node name found
-                       throw new InvalidXmlNodeException(array($this, $element, $attributes), XmlParser::EXCEPTION_XML_NODE_UNKNOWN);
+                       throw new InvalidXmlNodeException([$this, $element, $attributes], Parseable::EXCEPTION_XML_NODE_UNKNOWN);
                }
 
                // Call method
@@ -196,25 +199,22 @@ class MailTemplateEngine extends BaseTemplateEngine implements CompileableTempla
         * @return      void
         * @throws      XmlNodeMismatchException        If current main node mismatches the closing one
         */
-       public function finishElement ($resource, $nodeName) {
-               // Make all lower-case
-               $nodeName = strtolower($nodeName);
-
+       public function finishElement ($resource, string $nodeName) {
                // Does this match with current main node?
                //* DEBUG: */ echo "END: &gt;".$nodeName."&lt;<br />\n";
                if (($nodeName != $this->getCurrMainNode()) && (in_array($nodeName, $this->getMainNodes()))) {
                        // Did not match!
-                       throw new XmlNodeMismatchException (array($this, $nodeName, $this->getCurrMainNode()), XmlParser::EXCEPTION_XML_NODE_MISMATCH);
+                       throw new XmlNodeMismatchException (array($this, $nodeName, $this->getCurrMainNode()), Parseable::EXCEPTION_XML_NODE_MISMATCH);
                } elseif (in_array($nodeName, $this->getSubNodes())) {
                        // Silently ignore sub nodes
                        return;
                }
 
                // Construct method name
-               $methodName = 'finish' . self::convertToClassName($nodeName);
+               $methodName = 'finish' . StringUtils::convertToClassName($nodeName);
 
                // Call the corresponding method
-               call_user_func_array(array($this, $methodName), array());
+               call_user_func_array(array($this, $methodName), []);
        }
 
        /**
@@ -224,7 +224,7 @@ class MailTemplateEngine extends BaseTemplateEngine implements CompileableTempla
         * @param       $characters             Characters to handle
         * @return      void
         */
-       public function characterHandler ($resource, $characters) {
+       public function characterHandler ($resource, string $characters) {
                // Trim all spaces away
                $characters = trim($characters);
 
@@ -232,7 +232,7 @@ class MailTemplateEngine extends BaseTemplateEngine implements CompileableTempla
                if (empty($characters)) {
                        // Then skip it silently
                        return;
-               } // END - if
+               }
 
                // Add the message now
                $this->assignVariable('message', $characters);
@@ -265,7 +265,7 @@ class MailTemplateEngine extends BaseTemplateEngine implements CompileableTempla
         * @param       $senderAddress  Sender address to set in email
         * @return      void
         */
-       private function setEmailPropertySenderAddress ($senderAddress) {
+       private function setEmailPropertySenderAddress (string $senderAddress) {
                // Set the template variable
                $this->assignVariable('sender', $senderAddress);
        }
@@ -276,7 +276,7 @@ class MailTemplateEngine extends BaseTemplateEngine implements CompileableTempla
         * @param       $recipientAddress       Recipient address to set in email
         * @return      void
         */
-       private function setEmailPropertyRecipientAddress ($recipientAddress) {
+       private function setEmailPropertyRecipientAddress (string $recipientAddress) {
                // Set the template variable
                $this->assignVariable('recipient', $recipientAddress);
        }