Continued:
authorRoland Häder <roland@mxchange.org>
Wed, 2 Dec 2020 07:18:15 +0000 (08:18 +0100)
committerRoland Häder <roland@mxchange.org>
Wed, 2 Dec 2020 07:20:23 +0000 (08:20 +0100)
- introduced CompileableXmlTemplate class
- also BaseXmlTemplateEngine needs a trait

Signed-off-by: Roland Häder <roland@mxchange.org>
framework/main/classes/decorator/template/class_XmlRewriterTemplateDecorator.php
framework/main/classes/template/class_BaseTemplateEngine.php
framework/main/classes/template/image/class_ImageTemplateEngine.php
framework/main/classes/template/mail/class_MailTemplateEngine.php
framework/main/classes/template/menu/class_MenuTemplateEngine.php
framework/main/classes/template/xml/class_BaseXmlTemplateEngine.php
framework/main/interfaces/template/class_CompileableTemplate.php
framework/main/interfaces/template/xml/class_CompileableXmlTemplate.php [new file with mode: 0644]

index b4c51bf976fc753627773e569e0661b03589cd53..b119daafa90c606149b943543245176988db1a12 100644 (file)
@@ -5,7 +5,7 @@ namespace Org\Mxchange\CoreFramework\Template\Xml;
 // Import framework stuff
 use Org\Mxchange\CoreFramework\Generic\BaseDecorator;
 use Org\Mxchange\CoreFramework\Response\Responseable;
-use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
+use Org\Mxchange\CoreFramework\Template\Xml\CompileableXmlTemplate;
 use Org\Mxchange\CoreFramework\Traits\Template\CompileableTemplateTrait;
 
 /**
@@ -31,7 +31,7 @@ use Org\Mxchange\CoreFramework\Traits\Template\CompileableTemplateTrait;
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-class XmlRewriterTemplateDecorator extends BaseDecorator implements CompileableTemplate {
+class XmlRewriterTemplateDecorator extends BaseDecorator implements CompileableXmlTemplate {
        // Load traits
        use CompileableTemplateTrait;
 
@@ -48,10 +48,10 @@ class XmlRewriterTemplateDecorator extends BaseDecorator implements CompileableT
        /**
         * Creates an instance of the class TemplateEngine and prepares it for usage
         *
-        * @param       $innerTemplateInstance  A CompileableTemplate instance
+        * @param       $innerTemplateInstance  A CompileableXmlTemplate instance
         * @return      $templateInstance       An instance of TemplateEngine
         */
-       public static final function createXmlRewriterTemplateDecorator (CompileableTemplate $innerTemplateInstance) {
+       public static final function createXmlRewriterTemplateDecorator (CompileableXmlTemplate $innerTemplateInstance) {
                // Get a new instance
                $templateInstance = new XmlRewriterTemplateDecorator();
 
@@ -416,7 +416,7 @@ class XmlRewriterTemplateDecorator extends BaseDecorator implements CompileableT
         * @return      void
         * @todo        Find something useful with this!
         */
-       public function characterHandler ($resource, $characters) {
+       public function characterHandler ($resource, string $characters) {
                // Call the inner class' method but trim the characters before
                $this->getTemplateInstance()->characterHandler($resource, trim($characters));
        }
index 2d30141ec8004c9f1fc1190a5cdff3420b5cdda6..8c09dfbf91a01dfa65b5c601a73932a3500a3181 100644 (file)
@@ -170,11 +170,6 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         */
        private $languageSupport = true;
 
-       /**
-        * XML compacting is disabled by default
-        */
-       private $xmlCompacting = false;
-
        /**
         * Protected constructor
         *
@@ -1548,33 +1543,6 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                $this->setRawTemplateData($rawData);
        }
 
-       /**
-        * Renders the given XML content
-        *
-        * @param       $content        Valid XML content or if not set the current loaded raw content
-        * @return      void
-        * @throws      XmlParserException      If an XML error was found
-        */
-       public function renderXmlContent (string $content = NULL) {
-               // Is the content set?
-               if (is_null($content)) {
-                       // Get current content
-                       $content = $this->getRawTemplateData();
-               }
-
-               // Get a XmlParser instance
-               $parserInstance = ObjectFactory::createObjectByConfiguredName('xml_parser_class', array($this));
-
-               // Check if XML compacting is enabled
-               if ($this->isXmlCompactingEnabled()) {
-                       // Yes, so get a decorator class for transparent compacting
-                       $parserInstance = ObjectFactory::createObjectByConfiguredName('deco_compacting_xml_parser_class', array($parserInstance));
-               }
-
-               // Parse the XML document
-               $parserInstance->parseXmlContent($content);
-       }
-
        /**
         * Enables or disables language support
         *
@@ -1594,25 +1562,6 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                return $this->languageSupport;
        }
 
-       /**
-        * Enables or disables XML compacting
-        *
-        * @param       $xmlCompacting  New XML compacting setting
-        * @return      void
-        */
-       public final function enableXmlCompacting (bool $xmlCompacting = true) {
-               $this->xmlCompacting = $xmlCompacting;
-       }
-
-       /**
-        * Checks whether XML compacting is enabled
-        *
-        * @return      $xmlCompacting  Whether XML compacting is enabled or disabled
-        */
-       public final function isXmlCompactingEnabled () {
-               return $this->xmlCompacting;
-       }
-
        /**
         * Removes all commentd, tabs and new-line characters to compact the content
         *
index 6eeedefaf5d116fd2c0d934456af7edd2a60b579..07ba19bf1b99436cff2628d7c16e511db26d6e9d 100644 (file)
@@ -256,7 +256,7 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl
         * @return      void
         * @todo        Find something usefull with this!
         */
-       public function characterHandler ($resource, $characters) {
+       public function characterHandler ($resource, string $characters) {
                // Trim all spaces away
                $characters = trim($characters);
 
index 7406248eabd35166aabc0d318d88d9c9a80f3da8..6734da320e502c395dd76b549d247e004bf1a005 100644 (file)
@@ -226,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);
 
index 442f929072709ad26e68317a9dd80e123614623a..dcdf8cad96204943bcd60f13b11ec20441e361b1 100644 (file)
@@ -343,7 +343,7 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla
         * @return      void
         * @todo        Find something useful with this!
         */
-       public function characterHandler ($resource, $characters) {
+       public function characterHandler ($resource, string $characters) {
                // Trim all spaces away
                $characters = trim($characters);
 
index bf63126660a544485f14b14202657023f06f78ba..e86763777e99529537ef3cd5f4befdcb68b48a1a 100644 (file)
@@ -9,7 +9,9 @@ use Org\Mxchange\CoreFramework\Factory\Template\XmlTemplateEngineFactory;
 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
 use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
 use Org\Mxchange\CoreFramework\Template\Engine\BaseTemplateEngine;
+use Org\Mxchange\CoreFramework\Template\Xml\CompileableXmlTemplate;
 use Org\Mxchange\CoreFramework\Traits\Stacker\StackableTrait;
+use Org\Mxchange\CoreFramework\Traits\Template\CompileableTemplateTrait;
 use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
 
 // Import SPL stuff
@@ -38,8 +40,9 @@ use \InvalidArgumentException;
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-abstract class BaseXmlTemplateEngine extends BaseTemplateEngine {
+abstract class BaseXmlTemplateEngine extends BaseTemplateEngine implements CompileableXmlTemplate {
        // Load traits
+       use CompileableTemplateTrait;
        use StackableTrait;
 
        /**
@@ -78,9 +81,9 @@ abstract class BaseXmlTemplateEngine extends BaseTemplateEngine {
        protected $dependencyContent = [];
 
        /**
-        * Template engine instance
+        * XML compacting is disabled by default
         */
-       private $templateInstance = NULL;
+       private $xmlCompacting = false;
 
        /**
         * Protected constructor
@@ -237,25 +240,6 @@ abstract class BaseXmlTemplateEngine extends BaseTemplateEngine {
                return $this->subNodes;
        }
 
-       /**
-        * Setter for template engine instances
-        *
-        * @param       $templateInstance       An instance of a template engine class
-        * @return      void
-        */
-       protected final function setTemplateInstance (CompileableTemplate $templateInstance) {
-               $this->templateInstance = $templateInstance;
-       }
-
-       /**
-        * Getter for template engine instances
-        *
-        * @return      $templateInstance       An instance of a template engine class
-        */
-       protected final function getTemplateInstance () {
-               return $this->templateInstance;
-       }
-
        /**
         * Read XML variables by calling readVariable() with 'general' as
         * variable stack.
@@ -374,4 +358,50 @@ abstract class BaseXmlTemplateEngine extends BaseTemplateEngine {
                call_user_func_array(array($this, $methodName), array());
        }
 
+       /**
+        * Renders the given XML content
+        *
+        * @param       $content        Valid XML content or if not set the current loaded raw content
+        * @return      void
+        * @throws      XmlParserException      If an XML error was found
+        */
+       public function renderXmlContent (string $content = NULL) {
+               // Is the content set?
+               if (is_null($content)) {
+                       // Get current content
+                       $content = $this->getRawTemplateData();
+               }
+
+               // Get a XmlParser instance
+               $parserInstance = ObjectFactory::createObjectByConfiguredName('xml_parser_class', array($this));
+
+               // Check if XML compacting is enabled
+               if ($this->isXmlCompactingEnabled()) {
+                       // Yes, so get a decorator class for transparent compacting
+                       $parserInstance = ObjectFactory::createObjectByConfiguredName('deco_compacting_xml_parser_class', array($parserInstance));
+               }
+
+               // Parse the XML document
+               $parserInstance->parseXmlContent($content);
+       }
+
+       /**
+        * Enables or disables XML compacting
+        *
+        * @param       $xmlCompacting  New XML compacting setting
+        * @return      void
+        */
+       public final function enableXmlCompacting (bool $xmlCompacting = true) {
+               $this->xmlCompacting = $xmlCompacting;
+       }
+
+       /**
+        * Checks whether XML compacting is enabled
+        *
+        * @return      $xmlCompacting  Whether XML compacting is enabled or disabled
+        */
+       public final function isXmlCompactingEnabled () {
+               return $this->xmlCompacting;
+       }
+
 }
index 0c6636a18f7667a4fab3098b903145bd2c14d7e4..82ab8927e2993ea67da6654b4571d3ad8a8cebbf 100644 (file)
@@ -159,15 +159,6 @@ interface CompileableTemplate extends FrameworkInterface {
         */
        function renameVariable (string $oldName, string $newName);
 
-       /**
-        * Renders the given XML content
-        *
-        * @param       $content        Valid XML content or if not set the current loaded raw content
-        * @return      void
-        * @throws      XmlParserException      If an XML error was found
-        */
-       function renderXmlContent (string $content = NULL);
-
        /**
         * Enables or disables language support
         *
@@ -183,29 +174,6 @@ interface CompileableTemplate extends FrameworkInterface {
         */
        function isLanguageSupportEnabled ();
 
-       /**
-        * Enables or disables XML compacting
-        *
-        * @param       $xmlCompacting  New XML compacting setting
-        * @return      void
-        */
-       function enableXmlCompacting (bool $xmlCompacting = true);
-
-       /**
-        * Checks whether XML compacting is enabled
-        *
-        * @return      $xmlCompacting  Whether XML compacting is enabled or disabled
-        */
-       function isXmlCompactingEnabled ();
-
-       /**
-        * Removes all comments, tabs and new-line charcters to compact the content
-        *
-        * @param       $uncompactedContent             The uncompacted content
-        * @return      $compactedContent               The compacted content
-        */
-       function compactContent (string $uncompactedContent);
-
        /**
         * Getter for given variable group
         *
diff --git a/framework/main/interfaces/template/xml/class_CompileableXmlTemplate.php b/framework/main/interfaces/template/xml/class_CompileableXmlTemplate.php
new file mode 100644 (file)
index 0000000..7321a34
--- /dev/null
@@ -0,0 +1,64 @@
+<?php
+// Own namespace
+namespace Org\Mxchange\CoreFramework\Template\Xml;
+
+// Import framework stuff
+use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
+
+/**
+ * An interface for template engines
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @version            0.0.0
+ * @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
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+interface CompileableXmlTemplate extends CompileableTemplate {
+
+       /**
+        * Renders the given XML content
+        *
+        * @param       $content        Valid XML content or if not set the current loaded raw content
+        * @return      void
+        * @throws      XmlParserException      If an XML error was found
+        */
+       function renderXmlContent (string $content = NULL);
+
+       /**
+        * Enables or disables XML compacting
+        *
+        * @param       $xmlCompacting  New XML compacting setting
+        * @return      void
+        */
+       function enableXmlCompacting (bool $xmlCompacting = true);
+
+       /**
+        * Checks whether XML compacting is enabled
+        *
+        * @return      $xmlCompacting  Whether XML compacting is enabled or disabled
+        */
+       function isXmlCompactingEnabled ();
+
+       /**
+        * Removes all comments, tabs and new-line charcters to compact the content
+        *
+        * @param       $uncompactedContent             The uncompacted content
+        * @return      $compactedContent               The compacted content
+        */
+       function compactContent (string $uncompactedContent);
+
+}