]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/template/xml/class_BaseXmlTemplateEngine.php
Continued:
[core.git] / framework / main / classes / template / xml / class_BaseXmlTemplateEngine.php
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;
+       }
+
 }