]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/template/class_BaseTemplateEngine.php
Continued:
[core.git] / framework / main / classes / template / class_BaseTemplateEngine.php
index 721a0f6c47d316f476f27296927376730f0d121b..2460e54cdd9b637894145be3e4bf009e3c93c5f6 100644 (file)
@@ -6,6 +6,7 @@ namespace Org\Mxchange\CoreFramework\Template\Engine;
 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
 use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
+use Org\Mxchange\CoreFramework\Handler\Stream\IoHandler;
 use Org\Mxchange\CoreFramework\Filesystem\FileNotFoundException;
 use Org\Mxchange\CoreFramework\Generic\NullPointerException;
 use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
@@ -41,6 +42,11 @@ use \SplFileInfo;
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 abstract class BaseTemplateEngine extends BaseFrameworkSystem {
+       /**
+        * The file I/O instance for the template loader
+        */
+       private $fileIoInstance = NULL;
+
        /**
         * The local path name where all templates and sub folders for special
         * templates are stored. We will internally determine the language plus
@@ -195,7 +201,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $variableGroup  Optional variable group to look in
         * @return      $index                  false means not found, >=0 means found on a specific index
         */
-       private function getVariableIndex ($variableName, $variableGroup = NULL) {
+       private function getVariableIndex (string $variableName, string $variableGroup = NULL) {
                // Replace all dashes to underscores to match variables with configuration entries
                $variableName = trim(StringUtils::convertDashesToUnderscores($variableName));
 
@@ -207,7 +213,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                        // Use current group
                        //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(__METHOD__.' currGroup=' . $this->currGroup . ' set as stack!');
                        $variableGroup = $this->currGroup;
-               } // END - if
+               }
 
                // Is the group there?
                if ($this->isVarStackSet($variableGroup)) {
@@ -220,9 +226,9 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                                        //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(__METHOD__.':FOUND!');
                                        $found = $index;
                                        break;
-                               } // END - if
-                       } // END - foreach
-               } // END - if
+                               }
+                       }
+               }
 
                // Return the current position
                return $found;
@@ -234,7 +240,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $variableGroup  Variable group to check
         * @return      $isSet                  Whether the given variable group is set
         */
-       protected final function isVarStackSet ($variableGroup) {
+       protected final function isVarStackSet (string $variableGroup) {
                // Check it
                $isSet = isset($this->varStack[$variableGroup]);
 
@@ -248,7 +254,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $variableGroup  Variable group to check
         * @return      $varStack               Found variable group
         */
-       public final function getVarStack ($variableGroup) {
+       public final function getVarStack (string $variableGroup) {
                return $this->varStack[$variableGroup];
        }
 
@@ -259,7 +265,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $varStack               Variable stack to check
         * @return      void
         */
-       protected final function setVarStack ($variableGroup, array $varStack) {
+       protected final function setVarStack (string $variableGroup, array $varStack) {
                $this->varStack[$variableGroup]  = $varStack;
        }
 
@@ -270,7 +276,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $variableGroup  Optional variable group to look in
         * @return      $content                Content of the variable or null if not found
         */
-       protected function readVariable ($variableName, $variableGroup = NULL) {
+       protected function readVariable (string $variableName, string $variableGroup = NULL) {
                // Replace all dashes to underscores to match variables with configuration entries
                $variableName = trim(StringUtils::convertDashesToUnderscores($variableName));
 
@@ -282,7 +288,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                        // Use current group
                        //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(__METHOD__.' currGroup=' . $this->currGroup . ' set as stack!');
                        $variableGroup = $this->currGroup;
-               } // END - if
+               }
 
                // Get variable index
                $found = $this->getVariableIndex($variableName, $variableGroup);
@@ -291,7 +297,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                if ($found !== false) {
                        // Read it
                        $content = $this->getVariableValue($variableGroup, $found);
-               } // END - if
+               }
 
                // Return the current position
                //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(__METHOD__.': variableGroup=' . $variableGroup . ',variableName=' . $variableName . ', content[' . gettype($content) . ']=' . $content);
@@ -305,7 +311,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $value                  Value we want to store in the variable
         * @return      void
         */
-       private function addVariable ($variableName, $value) {
+       private function addVariable (string $variableName, $value) {
                // Set general variable group
                $this->setVariableGroup('general');
 
@@ -326,7 +332,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                if ($this->isVarStackSet($this->currGroup)) {
                        // Then use it
                        $result = $this->getVarStack($this->currGroup);
-               } // END - if
+               }
 
                // Return result
                return $result;
@@ -339,7 +345,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $add            Whether add this group
         * @return      void
         */
-       public function setVariableGroup ($groupName, $add = true) {
+       public function setVariableGroup (string $groupName, bool $add = true) {
                // Set group name
                //* DEBIG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(__METHOD__.': currGroup=' . $groupName);
                $this->currGroup = $groupName;
@@ -347,7 +353,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                // Skip group 'general'
                if (($groupName != 'general') && ($add === true)) {
                        $this->variableGroups[$groupName] = 'OK';
-               } // END - if
+               }
        }
 
 
@@ -358,7 +364,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $value                  Value to store in variable
         * @return      void
         */
-       public function addGroupVariable ($variableName, $value) {
+       public function addGroupVariable (string $variableName, $value) {
                // Replace all dashes to underscores to match variables with configuration entries
                $variableName = trim(StringUtils::convertDashesToUnderscores($variableName));
 
@@ -382,7 +388,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $index          Index in variable array
         * @return      $value          Value to set
         */
-       private function getVariableValue ($variableGroup, $index) {
+       private function getVariableValue (string $variableGroup, int $index) {
                // Return it
                return $this->varStack[$variableGroup][$index]['value'];
        }
@@ -395,7 +401,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @return      void
         * @throws      NoVariableException     If the given variable is not found
         */
-       private function modifyVariable ($variableName, $value) {
+       private function modifyVariable (string $variableName, $value) {
                // Replace all dashes to underscores to match variables with configuration entries
                $variableName = trim(StringUtils::convertDashesToUnderscores($variableName));
 
@@ -406,7 +412,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                if ($index === false) {
                        // Unset variables cannot be modified
                        throw new NoVariableException(array($this, $variableName, $value), self::EXCEPTION_VARIABLE_IS_MISSING);
-               } // END - if
+               }
 
                // Then modify it
                $this->setVariableValue($this->currGroup, $index, $value);
@@ -420,7 +426,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $value          Value to set
         * @return      void
         */
-       private function setVariableValue ($variableGroup, $index, $value) {
+       private function setVariableValue (string $variableGroup, int $index, $value) {
                $this->varStack[$variableGroup][$index]['value'] = $value;
        }
 
@@ -434,7 +440,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $value                  Value to set
         * @return      void
         */
-       protected function setVariable ($variableGroup, $variableName, $value) {
+       protected function setVariable (string $variableGroup, string $variableName, $value) {
                // Replace all dashes to underscores to match variables with configuration entries
                $variableName = trim(StringUtils::convertDashesToUnderscores($variableName));
 
@@ -447,7 +453,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                        if (!isset($this->varStack[$variableGroup])) {
                                // Then initialize it here
                                $this->varStack[$variableGroup] = array();
-                       } // END - if
+                       }
 
                        // Not found, add it
                        array_push($this->varStack[$variableGroup], $this->generateVariableArray($variableName, $value));
@@ -465,7 +471,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $value                  Value to set
         * @return      $varData                Variable data array
         */
-       private function generateVariableArray ($variableName, $value) {
+       private function generateVariableArray (string $variableName, $value) {
                // Replace all dashes to underscores to match variables with configuration entries
                $variableName = trim(StringUtils::convertDashesToUnderscores($variableName));
 
@@ -486,8 +492,8 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $templateType   The current template's type
         * @return      void
         */
-       protected final function setTemplateType ($templateType) {
-               $this->templateType = (string) $templateType;
+       protected final function setTemplateType (string $templateType) {
+               $this->templateType = $templateType;
        }
 
        /**
@@ -524,9 +530,9 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param               $templateBasePath               The relative base path for all templates
         * @return      void
         */
-       protected final function setTemplateBasePath ($templateBasePath) {
+       protected final function setTemplateBasePath (string $templateBasePath) {
                // And set it
-               $this->templateBasePath = (string) $templateBasePath;
+               $this->templateBasePath = $templateBasePath;
        }
 
        /**
@@ -556,9 +562,9 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         *                                                      templates
         * @return      void
         */
-       protected final function setRawTemplateExtension ($templateExtension) {
+       protected final function setRawTemplateExtension (string $templateExtension) {
                // And set it
-               $this->templateExtension = (string) $templateExtension;
+               $this->templateExtension = $templateExtension;
        }
 
        /**
@@ -568,9 +574,9 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         *                                                      templates
         * @return      void
         */
-       protected final function setCodeTemplateExtension ($codeExtension) {
+       protected final function setCodeTemplateExtension (string $codeExtension) {
                // And set it
-               $this->codeExtension = (string) $codeExtension;
+               $this->codeExtension = $codeExtension;
        }
 
        /**
@@ -602,9 +608,9 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         *                                                              templates
         * @return      void
         */
-       protected final function setCompileOutputPath ($compileOutputPath) {
+       protected final function setCompileOutputPath (string $compileOutputPath) {
                // And set it
-               $this->compileOutputPath = (string) $compileOutputPath;
+               $this->compileOutputPath = $compileOutputPath;
        }
 
        /**
@@ -614,18 +620,18 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $variableGroup  Variable group (default: currGroup)
         * @return      void
         */
-       protected final function unsetVariableStackOffset ($index, $variableGroup = NULL) {
+       protected final function unsetVariableStackOffset (int $index, string $variableGroup = NULL) {
                // Is the variable group not set?
                if (is_null($variableGroup)) {
                        // Then set it to current
                        $variableGroup = $this->currGroup;
-               } // END - if
+               }
 
                // Is the entry there?
                if (!isset($this->varStack[$variableGroup][$index])) {
                        // Abort here, we need fixing!
                        $this->debugInstance();
-               } // END - if
+               }
 
                // Remove it
                unset($this->varStack[$variableGroup][$index]);
@@ -637,11 +643,11 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $rawTemplateData        The raw data from the template
         * @return      void
         */
-       protected final function setRawTemplateData ($rawTemplateData) {
+       protected final function setRawTemplateData (string $rawTemplateData) {
                // And store it in this class
                //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(__METHOD__.': ' . strlen($rawTemplateData) . ' Bytes set.');
                //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(__METHOD__.': ' . $this->currGroup . ' variables: ' . count($this->getVarStack($this->currGroup)) . ', groups=' . count($this->varStack));
-               $this->rawTemplateData = (string) $rawTemplateData;
+               $this->rawTemplateData = $rawTemplateData;
        }
 
        /**
@@ -657,12 +663,13 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
        /**
         * Private setter for compiled templates
         *
+        * @param       $compiledData   Compiled template data
         * @return      void
         */
-       private final function setCompiledData ($compiledData) {
+       private final function setCompiledData (string $compiledData) {
                // And store it in this class
                //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: ' . strlen($compiledData) . ' Bytes set.');
-               $this->compiledData = (string) $compiledData;
+               $this->compiledData = $compiledData;
        }
 
        /**
@@ -683,14 +690,14 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @return      void
         * @throws      FileNotFoundException   If the template was not found
         */
-       protected function loadTemplate ($templateName, $extOther = '') {
+       protected function loadTemplate (string $templateName, string $extOther = '') {
                // Get extension for the template if empty
                if (empty($extOther)) {
                        // None provided, so get the raw one
                        $ext = $this->getRawTemplateExtension();
                } else {
                        // Then use it!
-                       $ext = (string) $extOther;
+                       $ext = $extOther;
                }
 
                /*
@@ -734,10 +741,8 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @return      void
         */
        private function loadRawTemplateData (SplFileInfo $fileInstance) {
-               // Some debug code to look on the file which is being loaded
-               //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: fileInstance=' . $fileInstance);
-
                // Load the raw template
+               //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: fileInstance=' . $fileInstance);
                $rawTemplateData = $this->getFileIoInstance()->loadFileContents($fileInstance);
 
                // Store the template's contents into this class
@@ -751,18 +756,16 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * Try to assign an extracted template variable as a "content" or 'config'
         * variable.
         *
-        * @param       $variableName           The variable's name (shall be content or config)
+        * @param       $variableName   The variable's name (shall be content or config)
         *                                                      by default
         * @param       $variableName   The variable we want to assign
         * @return      void
         */
-       private function assignTemplateVariable ($variableName, $var) {
+       private function assignTemplateVariable (string $variableName, $var) {
                // Replace all dashes to underscores to match variables with configuration entries
+               //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: variableName=' . $variableName . ',var=' . $var);
                $variableName = trim(StringUtils::convertDashesToUnderscores($variableName));
 
-               // Debug message
-               //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: variableName=' . $variableName . ',variableName=' . $variableName);
-
                // Is it not a config variable?
                if ($variableName != 'config') {
                        // Regular template variables
@@ -779,15 +782,10 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $rawData        The raw template data we shall analyze
         * @return      void
         */
-       private function extractVariablesFromRawData ($rawData) {
-               // Cast to string
-               $rawData = (string) $rawData;
-
+       private function extractVariablesFromRawData (string $rawData) {
                // Search for variables
-               preg_match_all('/\$(\w+)(\[(\w+)\])?/', $rawData, $variableMatches);
-
-               // Debug message
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:rawData(' . strlen($rawData) . ')=' . $rawData . ',variableMatches=' . print_r($variableMatches, true));
+               preg_match_all('/\$(\w+)(\[(\w+)\])?/', $rawData, $variableMatches);
 
                // Did we find some variables?
                if ((is_array($variableMatches)) && (count($variableMatches) == 4) && (count($variableMatches[0]) > 0)) {
@@ -800,9 +798,9 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                                if (!empty($var)) {
                                        // Try to assign it, empty strings are being ignored
                                        $this->assignTemplateVariable($variableName, $var);
-                               } // END - if
-                       } // END - foreach
-               } // END - if
+                               }
+                       }
+               }
        }
 
        /**
@@ -828,7 +826,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                        // Initialize both
                        $this->loadedRawData = array();
                        $this->rawTemplates = array();
-               } // END - if
+               }
 
                // Load all requested templates
                foreach ($templateMatches[1] as $template) {
@@ -860,8 +858,8 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                                                array_push($this->rawTemplates, $template);
                                        }
                                }
-                       } // END - if
-               } // END - foreach
+                       }
+               }
 
                // Restore the raw template data
                $this->setRawTemplateData($backup);
@@ -874,12 +872,12 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $template       The template's name
         * @return      void
         */
-       private function compileCode ($code, $template) {
+       private function compileCode (string $code, string $template) {
                // Is this template already compiled?
                if (in_array($template, $this->compiledTemplates)) {
                        // Abort here...
                        return;
-               } // END - if
+               }
 
                // Remember this template being compiled
                array_push($this->compiledTemplates, $template);
@@ -927,8 +925,8 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
 
                                // Set the new raw data
                                $this->setRawTemplateData($rawData);
-                       } // END - if
-               } // END - foreach
+                       }
+               }
        }
 
        /**
@@ -958,8 +956,8 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                                        // This template was never found. We silently ignore it
                                        unset($this->rawTemplates[$key]);
                                }
-                       } // END - foreach
-               } // END - if
+                       }
+               }
        }
 
        /**
@@ -985,7 +983,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                        if (substr($varMatches[2][$key], 0, 1) == '=') {
                                // Remove and cast it
                                $varMatches[2][$key] = (string) substr($varMatches[2][$key], 1);
-                       } // END - if
+                       }
 
                        // Do we have some quotes left and right side? Then it is free text
                        if ((substr($varMatches[2][$key], 0, 1) == '"') && (substr($varMatches[2][$key], -1, 1) == '"')) {
@@ -995,7 +993,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                                // @TODO Non-string found so we need some deeper analysis...
                                ApplicationEntryPoint::exitApplication('Deeper analysis not yet implemented!');
                        }
-               } // END - foreach
+               }
        }
 
        /**
@@ -1020,7 +1018,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                                        // Then skip it
                                        //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: Template ' . $template . ' already compiled. SKIPPED!');
                                        continue;
-                               } // END - if
+                               }
 
                                // Search for the template
                                $foundIndex = array_search($template, $templateMatches[1]);
@@ -1033,15 +1031,15 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
 
                                        // Assign all variables
                                        $this->assignAllVariables($varMatches);
-                               } // END - if (isset($templateMatches ...
+                               }
 
                                // Compile the loaded template
                                $this->compileCode($code, $template);
-                       } // END - foreach ($this->loadedRawData ...
+                       }
 
                        // Insert all templates
                        $this->insertAllTemplates($templateMatches);
-               } // END - if (count($this->loadedRawData) ...
+               }
        }
 
        /**
@@ -1072,7 +1070,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                        // Abort here silently
                        // @TODO This silent abort should be logged, maybe.
                        return;
-               } // END - if
+               }
 
                // Walk through all variables
                foreach ($this->getVarStack('general') as $currEntry) {
@@ -1086,11 +1084,10 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
 
                        // The new behaviour
                        $content = str_replace('{?' . $currEntry['name'] . '?}', $currEntry['value'], $content);
-               } // END - for
-
-               //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: content after=' . strlen($content) . ' (' . md5($content) . ')');
+               }
 
                // Set the content back
+               //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: content after=' . strlen($content) . ' (' . md5($content) . ')');
                $this->setRawTemplateData($content);
        }
 
@@ -1101,7 +1098,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         *                                              'html' by default
         * @return      void
         */
-       public function loadHtmlTemplate ($template) {
+       public function loadHtmlTemplate (string $template) {
                // Set template type
                $this->setTemplateType($this->getConfigInstance()->getConfigEntry('html_template_type'));
 
@@ -1115,15 +1112,11 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $variableName   The variable we are looking for
         * @param       $value                  The value we want to store in the variable
         * @return      void
-        * @throws      NullPointerException    If $variableName is NULL
         * @throws      InvalidArgumentException        If the variable name is left empty
         */
-       public final function assignVariable ($variableName, $value) {
+       public final function assignVariable (string $variableName, $value) {
                // Validate parameter
-               if (is_null($variableName)) {
-                       // Throw NPE
-                       throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
-               } elseif (empty($variableName)) {
+               if (empty($variableName)) {
                        // Throw an exception
                        throw new InvalidArgumentException('Parameter "variableName" is empty');
                }
@@ -1153,7 +1146,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $variableGroup  Name of variable group (default: 'general')
         * @return      void
         */
-       public final function removeVariable ($variableName, $variableGroup = 'general') {
+       public final function removeVariable (string $variableName, string $variableGroup = 'general') {
                // First search for the variable if it was already added
                $index = $this->getVariableIndex($variableName, $variableGroup);
 
@@ -1162,7 +1155,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                        // Remove this variable
                        //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:UNSET: variableGroup=' . $variableGroup . ',variableName=' . $variableName . ',index=' . $index);
                        $this->unsetVariableStackOffset($index, $variableGroup);
-               } // END - if
+               }
        }
 
        /**
@@ -1172,7 +1165,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $variableName   Name of the variable we want to assign
         * @return      void
         */
-       public function assignTemplateWithVariable ($templateName, $variableName) {
+       public function assignTemplateWithVariable (string $templateName, string $variableName) {
                // Get the content from last loaded raw template
                $content = $this->getRawTemplateData();
 
@@ -1189,7 +1182,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $variableName   The configuration variable we want to assign
         * @return      void
         */
-       public function assignConfigVariable ($variableName) {
+       public function assignConfigVariable (string $variableName) {
                // Replace all dashes to underscores to match variables with configuration entries
                $variableName = trim(StringUtils::convertDashesToUnderscores($variableName));
 
@@ -1213,7 +1206,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                foreach ($variables as $name => $value) {
                        // Set variable with name for 'config' group
                        $this->assignVariable($name, $value);
-               } // END - foreach
+               }
        }
 
        /**
@@ -1245,7 +1238,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         *                                              located in 'code' by default
         * @return      void
         */
-       public function loadCodeTemplate ($template) {
+       public function loadCodeTemplate (string $template) {
                // Set template type
                $this->setTemplateType($this->getConfigInstance()->getConfigEntry('code_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_template_type'));
 
@@ -1260,7 +1253,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         *                                              located in 'emails' by default
         * @return      void
         */
-       public function loadEmailTemplate ($template) {
+       public function loadEmailTemplate (string $template) {
                // Set template type
                $this->setTemplateType($this->getConfigInstance()->getConfigEntry('email_template_type'));
 
@@ -1281,7 +1274,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                        // Abort here silently
                        //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: Aborted, variable stack general not found!');
                        return;
-               } // END - if
+               }
 
                // Iterate through all general variables
                foreach ($this->getVarStack('general') as $index => $currVariable) {
@@ -1303,7 +1296,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                                // Re-assign the value directly
                                $this->assignVariable($currVariable['name'], $value);
                        }
-               } // END - foreach
+               }
        }
 
        /**
@@ -1322,7 +1315,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                        // Transfer it's name/value combination to the $content array
                        //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:' . $currVariable['name'] . '=<pre>' . htmlentities($currVariable['value']).'</pre>');
                        $dummy[$currVariable['name']] = $currVariable['value'];
-               }// END - if
+               }
 
                // Set the new variable (don't remove the second dollar!)
                $$validVar = $dummy;
@@ -1359,7 +1352,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
 
                                // And put all together
                                $eval = sprintf('%s<%%php %s %%>%s', $evalLeft, $evalMiddle, $evalRight);
-                       } // END - while
+                       }
 
                        // Prepare PHP code for eval() command
                        $eval = str_replace(
@@ -1381,12 +1374,12 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
 
                                // Output backtrace here
                                $this->debugBackTrace();
-                       } // END - if
+                       }
 
                        // Set raw template data
                        $this->setRawTemplateData($result);
                        $cnt++;
-               } // END - while
+               }
 
                // Final variable assignment
                $this->finalizeVariableCompilation();
@@ -1412,7 +1405,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                if (substr($this->getTemplateType(), 0, strlen($codeType)) != $codeType) {
                        // Abort here
                        throw new UnexpectedTemplateTypeException(array($this, $this->getTemplateType(), $this->getConfigInstance()->getConfigEntry('code_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_template_type')), self::EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED);
-               } // END - if
+               }
 
                // Get the raw data.
                $rawData = $this->getRawTemplateData();
@@ -1449,8 +1442,8 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
 
                                // Remove the raw template content as well
                                $this->setRawTemplateData('');
-                       } // END - if
-               } // END - if($templateMatches ...
+                       }
+               }
        }
 
        /**
@@ -1459,7 +1452,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $helperName             The helper's name
         * @return      void
         */
-       protected function loadViewHelper ($helperName) {
+       protected function loadViewHelper (string $helperName) {
                // Is this view helper loaded?
                if (!isset($this->helpers[$helperName])) {
                        // Create a class name
@@ -1467,7 +1460,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
 
                        // Generate new instance
                        $this->helpers[$helperName] = ObjectFactory::createObjectByName($className);
-               } // END - if
+               }
 
                // Return the requested instance
                return $this->helpers[$helperName];
@@ -1491,7 +1484,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $setMatchAsCode         Sets $match if readVariable() returns empty result
         * @return      $rawCode        Compile code with inserted variable value
         */
-       public function compileRawCode ($rawCode, $setMatchAsCode=false) {
+       public function compileRawCode (string $rawCode, bool $setMatchAsCode = false) {
                // Find the variables
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:rawCode=<pre>' . htmlentities($rawCode) . '</pre>');
                preg_match_all($this->regExpVarValue, $rawCode, $varMatches);
@@ -1521,8 +1514,8 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                                        // Insert value
                                        $rawCode = str_replace($varCode, $value, $rawCode);
                                }
-                       } // END - if
-               } // END - foreach
+                       }
+               }
 
                // Return the compiled data
                //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:rawCode=<pre>' . htmlentities($rawCode) . '</pre>');
@@ -1545,7 +1538,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $newName        New name of variable
         * @return      void
         */
-       public function renameVariable ($oldName, $newName) {
+       public function renameVariable (string $oldName, string $newName) {
                //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: oldName=' . $oldName . ', newName=' . $newName);
                // Get raw template code
                $rawData = $this->getRawTemplateData();
@@ -1564,12 +1557,12 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @return      void
         * @throws      XmlParserException      If an XML error was found
         */
-       public function renderXmlContent ($content = NULL) {
+       public function renderXmlContent (string $content = NULL) {
                // Is the content set?
                if (is_null($content)) {
                        // Get current content
                        $content = $this->getRawTemplateData();
-               } // END - if
+               }
 
                // Get a XmlParser instance
                $parserInstance = ObjectFactory::createObjectByConfiguredName('xml_parser_class', array($this));
@@ -1578,7 +1571,7 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                if ($this->isXmlCompactingEnabled()) {
                        // Yes, so get a decorator class for transparent compacting
                        $parserInstance = ObjectFactory::createObjectByConfiguredName('deco_compacting_xml_parser_class', array($parserInstance));
-               } // END - if
+               }
 
                // Parse the XML document
                $parserInstance->parseXmlContent($content);
@@ -1590,8 +1583,8 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $languageSupport        New language support setting
         * @return      void
         */
-       public final function enableLanguageSupport ($languageSupport = true) {
-               $this->languageSupport = (bool) $languageSupport;
+       public final function enableLanguageSupport (bool $languageSupport = true) {
+               $this->languageSupport = $languageSupport;
        }
 
        /**
@@ -1609,8 +1602,8 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $xmlCompacting  New XML compacting setting
         * @return      void
         */
-       public final function enableXmlCompacting ($xmlCompacting = true) {
-               $this->xmlCompacting = (bool) $xmlCompacting;
+       public final function enableXmlCompacting (bool $xmlCompacting = true) {
+               $this->xmlCompacting = $xmlCompacting;
        }
 
        /**
@@ -1622,13 +1615,32 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                return $this->xmlCompacting;
        }
 
+       /**
+        * Private getter for file IO instance
+        *
+        * @return      $fileIoInstance         An instance to the file I/O sub-system
+        */
+       protected final function getFileIoInstance () {
+               return $this->fileIoInstance;
+       }
+
+       /**
+        * Setter for file I/O instance
+        *
+        * @param       $fileIoInstance         An instance to the file I/O sub-system
+        * @return      void
+        */
+       public final function setFileIoInstance (IoHandler $fileIoInstance) {
+               $this->fileIoInstance = $fileIoInstance;
+       }
+
        /**
         * Removes all commentd, tabs and new-line characters to compact the content
         *
         * @param       $uncompactedContent             The uncompacted content
         * @return      $compactedContent               The compacted content
         */
-       public function compactContent ($uncompactedContent) {
+       public function compactContent (string $uncompactedContent) {
                // First, remove all tab/new-line/revert characters
                $compactedContent = str_replace(chr(9), '', str_replace(chr(10), '', str_replace(chr(13), '', $uncompactedContent)));
 
@@ -1641,8 +1653,8 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem {
                        foreach ($matches[0] as $match) {
                                // Remove the match
                                $compactedContent = str_replace($match, '', $compactedContent);
-                       } // END - foreach
-               } // END - if
+                       }
+               }
 
                // Set the content again
                $this->setRawTemplateData($compactedContent);