]> 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 8f031a85419d6b31f5616f78b8d6de02c8eaab11..6734da320e502c395dd76b549d247e004bf1a005 100644 (file)
@@ -1,18 +1,27 @@
 <?php
 // Own namespace
-namespace CoreFramework\Template\Engine;
+namespace Org\Mxchange\CoreFramework\Template\Engine;
 
 // Import framework stuff
-use CoreFramework\Registry\Registry;
-use CoreFramework\Response\Responseable;
-use CoreFramework\Template\CompileableTemplate;
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
+use Org\Mxchange\CoreFramework\Filesystem\InvalidDirectoryException;
+use Org\Mxchange\CoreFramework\Mailer\DeliverableMail;
+use Org\Mxchange\CoreFramework\Parser\Parseable;
+use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
+use Org\Mxchange\CoreFramework\Response\Responseable;
+use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
+use Org\Mxchange\CoreFramework\Template\Engine\BaseTemplateEngine;
+use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
+
+// Import SPL stuff
+use \UnexpectedValueException;
 
 /**
  * The own template engine for loading caching and sending out images
  *
  * @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 - 2020 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()
@@ -34,19 +43,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
@@ -66,15 +75,17 @@ class MailTemplateEngine extends BaseTemplateEngine implements CompileableTempla
        protected function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
+
+               // Set template type
+               $this->setTemplateType('mail');
        }
 
        /**
         * Creates an instance of the class TemplateEngine and prepares it for usage
         *
         * @return      $templateInstance               An instance of TemplateEngine
-        * @throws      BasePathIsEmptyException                If the provided $templateBasePath is empty
-        * @throws      InvalidBasePathStringException  If $templateBasePath is no string
-        * @throws      BasePathIsNoDirectoryException  If $templateBasePath is no
+        * @throws      UnexpectedValueException                If the provided $templateBasePath is empty or no string
+        * @throws      InvalidDirectoryException       If $templateBasePath is no
         *                                                                                      directory or not found
         * @throws      BasePathReadProtectedException  If $templateBasePath is
         *                                                                                      read-protected
@@ -84,21 +95,21 @@ class MailTemplateEngine extends BaseTemplateEngine implements CompileableTempla
                $templateInstance = new MailTemplateEngine();
 
                // Get the application instance from registry
-               $applicationInstance = Registry::getRegistry()->getInstance('app');
+               $applicationInstance = GenericRegistry::getRegistry()->getInstance('application');
 
                // Determine base path
-               $templateBasePath = $templateInstance->getConfigInstance()->getConfigEntry('application_base_path') . $applicationInstance->getRequestInstance()->getRequestElement('app') . '/';
+               $templateBasePath = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('application_base_path') . $applicationInstance->getAppShortName(). '/';
 
                // Is the base path valid?
                if (empty($templateBasePath)) {
                        // Base path is empty
-                       throw new BasePathIsEmptyException($templateInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+                       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 InvalidBasePathStringException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_STRING);
+                       throw new UnexpectedValueException(sprintf('[%s:%d] %s is not a string with a base path.', $templateInstance->__toString(), __LINE__, $templateBasePath), self::EXCEPTION_INVALID_STRING);
                } elseif (!is_dir($templateBasePath)) {
                        // Is not a path
-                       throw new BasePathIsNoDirectoryException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME);
+                       throw new InvalidDirectoryException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME);
                } elseif (!is_readable($templateBasePath)) {
                        // Is not readable
                        throw new BasePathReadProtectedException(array($templateInstance, $templateBasePath), self::EXCEPTION_READ_PROTECED_PATH);
@@ -108,11 +119,14 @@ 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($templateInstance->getConfigInstance()->getConfigEntry('base_path') . $templateInstance->getConfigInstance()->getConfigEntry('compile_output_path'));
+               $templateInstance->setCompileOutputPath(sprintf('%s%s/',
+                       $templateBasePath,
+                       FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('compile_output_path')
+               ));
 
                // Return the prepared instance
                return $templateInstance;
@@ -154,7 +168,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';
 
@@ -165,13 +179,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(array($this, $element, $attributes), Parseable::EXCEPTION_XML_NODE_UNKNOWN);
                }
 
                // Call method
@@ -187,25 +201,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), []);
        }
 
        /**
@@ -215,7 +226,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);
 
@@ -318,21 +329,6 @@ class MailTemplateEngine extends BaseTemplateEngine implements CompileableTempla
                $this->getMailerInstance()->invokeMailDelivery();
        }
 
-       /**
-        * Getter for image cache file (FQFN)
-        *
-        * @return      $fqfn   Full-qualified file name of the image cache
-        * @todo        0% done
-        */
-       public function getMailCacheFqfn () {
-               // Initialize FQFN
-               $fqfn = '';
-               $this->debugBackTrace('Unfinished area!');
-
-               // Return it
-               return $fqfn;
-       }
-
        /**
         * Setter for mailer instance
         *