X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=framework%2Fmain%2Fclasses%2Ftemplate%2Fclass_BaseTemplateEngine.php;h=6cadd99610aef89778177a3aac5abb86cfd32ae2;hb=2218902056efcf9a2c66fe7c24995e066bd7cd11;hp=cdd906716e18d1d0f5915ec9edbff8d34c9787fe;hpb=ff1654c67afda9c43f4fe7a3bc9bc376a38cae01;p=core.git diff --git a/framework/main/classes/template/class_BaseTemplateEngine.php b/framework/main/classes/template/class_BaseTemplateEngine.php index cdd90671..6cadd996 100644 --- a/framework/main/classes/template/class_BaseTemplateEngine.php +++ b/framework/main/classes/template/class_BaseTemplateEngine.php @@ -1,23 +1,31 @@ * @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 * @@ -34,7 +42,16 @@ use CoreFramework\Response\Responseable; * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class BaseTemplateEngine extends BaseFrameworkSystem { +abstract class BaseTemplateEngine extends BaseFrameworkSystem { + // Load traits + use IoHandlerTrait; + + // Exception codes for the template engine + const EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED = 0x110; + const EXCEPTION_TEMPLATE_CONTAINS_INVALID_VAR = 0x111; + const EXCEPTION_INVALID_VIEW_HELPER = 0x112; + const EXCEPTION_VARIABLE_IS_MISSING = 0x113; + /** * The local path name where all templates and sub folders for special * templates are stored. We will internally determine the language plus @@ -78,24 +95,24 @@ class BaseTemplateEngine extends BaseFrameworkSystem { private $compiledData = ''; /** - * The last loaded template's FQFN for debugging the engine + * The last loaded template's file instance (SplFileInfo) */ - private $lastTemplate = ''; + private $lastTemplate = NULL; /** * The variable stack for the templates */ - private $varStack = array(); + private $varStack = []; /** * Loaded templates for recursive protection and detection */ - private $loadedTemplates = array(); + private $loadedTemplates = []; /** * Compiled templates for recursive protection and detection */ - private $compiledTemplates = array(); + private $compiledTemplates = []; /** * Loaded raw template data @@ -127,7 +144,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { /** * Loaded helpers */ - private $helpers = array(); + private $helpers = []; /** * Current variable group @@ -137,7 +154,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { /** * All template groups except "general" */ - private $variableGroups = array(); + private $variableGroups = []; /** * Code begin @@ -154,24 +171,13 @@ class BaseTemplateEngine extends BaseFrameworkSystem { */ private $languageSupport = true; - /** - * XML compacting is disabled by default - */ - private $xmlCompacting = false; - - // Exception codes for the template engine - const EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED = 0x110; - const EXCEPTION_TEMPLATE_CONTAINS_INVALID_VAR = 0x111; - const EXCEPTION_INVALID_VIEW_HELPER = 0x112; - const EXCEPTION_VARIABLE_IS_MISSING = 0x113; - /** * Protected constructor * * @param $className Name of the class * @return void */ - protected function __construct ($className) { + protected function __construct (string $className) { // Call parent constructor parent::__construct($className); @@ -189,9 +195,9 @@ 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(self::convertDashesToUnderscores($variableName)); + $variableName = trim(StringUtils::convertDashesToUnderscores($variableName)); // First everything is not found $found = false; @@ -201,7 +207,7 @@ 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)) { @@ -214,9 +220,9 @@ 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; @@ -228,7 +234,7 @@ 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]); @@ -242,7 +248,7 @@ 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]; } @@ -253,7 +259,7 @@ 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; } @@ -264,9 +270,9 @@ 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(self::convertDashesToUnderscores($variableName)); + $variableName = trim(StringUtils::convertDashesToUnderscores($variableName)); // First everything is not found $content = NULL; @@ -276,7 +282,7 @@ 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); @@ -285,7 +291,7 @@ 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); @@ -299,7 +305,7 @@ 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'); @@ -314,13 +320,13 @@ class BaseTemplateEngine extends BaseFrameworkSystem { */ private function readCurrentGroup () { // Default is not found - $result = array(); + $result = []; // Is the group there? if ($this->isVarStackSet($this->currGroup)) { // Then use it $result = $this->getVarStack($this->currGroup); - } // END - if + } // Return result return $result; @@ -333,7 +339,7 @@ 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; @@ -341,7 +347,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // Skip group 'general' if (($groupName != 'general') && ($add === true)) { $this->variableGroups[$groupName] = 'OK'; - } // END - if + } } @@ -352,9 +358,9 @@ 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(self::convertDashesToUnderscores($variableName)); + $variableName = trim(StringUtils::convertDashesToUnderscores($variableName)); // Debug message //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(__METHOD__.': group=' . $this->currGroup . ', variableName=' . $variableName . ', value=' . $value); @@ -376,7 +382,7 @@ 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']; } @@ -389,9 +395,9 @@ 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(self::convertDashesToUnderscores($variableName)); + $variableName = trim(StringUtils::convertDashesToUnderscores($variableName)); // Get index for variable $index = $this->getVariableIndex($variableName); @@ -400,7 +406,7 @@ 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); @@ -414,7 +420,7 @@ 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; } @@ -428,9 +434,9 @@ 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(self::convertDashesToUnderscores($variableName)); + $variableName = trim(StringUtils::convertDashesToUnderscores($variableName)); // Get index for variable $index = $this->getVariableIndex($variableName); @@ -440,8 +446,8 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // Is the stack there? if (!isset($this->varStack[$variableGroup])) { // Then initialize it here - $this->varStack[$variableGroup] = array(); - } // END - if + $this->varStack[$variableGroup] = []; + } // Not found, add it array_push($this->varStack[$variableGroup], $this->generateVariableArray($variableName, $value)); @@ -459,9 +465,9 @@ 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(self::convertDashesToUnderscores($variableName)); + $variableName = trim(StringUtils::convertDashesToUnderscores($variableName)); // Generate the temporary array $varData = array( @@ -480,8 +486,8 @@ 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; } /** @@ -494,17 +500,17 @@ class BaseTemplateEngine extends BaseFrameworkSystem { } /** - * Setter for the last loaded template's FQFN + * Setter for the last loaded template's file instance * * @param $template The last loaded template * @return void */ - private final function setLastTemplate ($template) { - $this->lastTemplate = (string) $template; + private final function setLastTemplate (SplFileInfo $fileInstance) { + $this->lastTemplate = $fileInstance; } /** - * Getter for the last loaded template's FQFN + * Getter for the last loaded template's file instance * * @return $template The last loaded template */ @@ -518,9 +524,9 @@ 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; } /** @@ -550,9 +556,9 @@ 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; } /** @@ -562,9 +568,9 @@ 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; } /** @@ -596,9 +602,9 @@ 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; } /** @@ -608,18 +614,18 @@ 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]); @@ -631,11 +637,11 @@ 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; } /** @@ -644,19 +650,20 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * @return $rawTemplateData The raw data from the template */ public final function getRawTemplateData () { - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']: ' . strlen($this->rawTemplateData) . ' Bytes read.'); + //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: ' . strlen($this->rawTemplateData) . ' Bytes read.'); return $this->rawTemplateData; } /** * 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[' . __METHOD__ . ':' . __LINE__ . ']: ' . strlen($compiledData) . ' Bytes set.'); - $this->compiledData = (string) $compiledData; + //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: ' . strlen($compiledData) . ' Bytes set.'); + $this->compiledData = $compiledData; } /** @@ -665,7 +672,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * @return $compiledData Compiled template data */ public final function getCompiledData () { - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']: ' . strlen($this->compiledData) . ' Bytes read.'); + //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: ' . strlen($this->compiledData) . ' Bytes read.'); return $this->compiledData; } @@ -677,14 +684,14 @@ 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; } /* @@ -692,22 +699,22 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * now entirely done by php_intl. These old thing with language-based * template paths comes from an older time. */ - $fqfn = sprintf('%s%s%s%s%s%s', + $fileInstance = new SplFileInfo(sprintf('%s%s%s%s%s%s', $this->getTemplateBasePath(), $this->getGenericBasePath(), $this->getTemplateType(), DIRECTORY_SEPARATOR, (string) $templateName, $ext - ); + )); // First try this try { // Load the raw template data - $this->loadRawTemplateData($fqfn); + $this->loadRawTemplateData($fileInstance); } catch (FileNotFoundException $e) { // If we shall load a code-template we need to switch the file extension - if (($this->getTemplateType() != $this->getConfigInstance()->getConfigEntry('html_template_type')) && (empty($extOther))) { + if (($this->getTemplateType() != FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('html_template_type')) && (empty($extOther))) { // Switch over to the code-template extension and try it again $ext = $this->getCodeTemplateExtension(); @@ -715,7 +722,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { $this->loadTemplate($templateName, $ext); } else { // Throw it again - throw new FileNotFoundException($fqfn, self::EXCEPTION_FILE_NOT_FOUND); + throw new FileNotFoundException($fileInstance, self::EXCEPTION_FILE_NOT_FOUND); } } @@ -724,38 +731,34 @@ class BaseTemplateEngine extends BaseFrameworkSystem { /** * A private loader for raw template names * - * @param $fqfn The full-qualified file name for a template + * @param $fileInstance An instance of a SplFileInfo class * @return void */ - private function loadRawTemplateData ($fqfn) { - // Some debug code to look on the file which is being loaded - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']: FQFN=' . $fqfn); - + private function loadRawTemplateData (SplFileInfo $fileInstance) { // Load the raw template - $rawTemplateData = $this->getFileIoInstance()->loadFileContents($fqfn); + //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: fileInstance=' . $fileInstance); + $rawTemplateData = $this->getFileIoInstance()->loadFileContents($fileInstance); // Store the template's contents into this class $this->setRawTemplateData($rawTemplateData); - // Remember the template's FQFN - $this->setLastTemplate($fqfn); + // Remember the template's file instance + $this->setLastTemplate($fileInstance); } /** * 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 - $variableName = trim(self::convertDashesToUnderscores($variableName)); - - // Debug message - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']: variableName=' . $variableName . ',variableName=' . $variableName); + //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: variableName=' . $variableName . ',var=' . $var); + $variableName = trim(StringUtils::convertDashesToUnderscores($variableName)); // Is it not a config variable? if ($variableName != 'config') { @@ -773,16 +776,11 @@ 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 + //* 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); - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']:rawData(' . strlen($rawData) . ')=' . $rawData . ',variableMatches=' . print_r($variableMatches, true)); - // Did we find some variables? if ((is_array($variableMatches)) && (count($variableMatches) == 4) && (count($variableMatches[0]) > 0)) { // Initialize all missing variables @@ -794,9 +792,9 @@ 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 + } + } + } } /** @@ -820,9 +818,9 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // Initialize some arrays if (is_null($this->loadedRawData)) { // Initialize both - $this->loadedRawData = array(); - $this->rawTemplates = array(); - } // END - if + $this->loadedRawData = []; + $this->rawTemplates = []; + } // Load all requested templates foreach ($templateMatches[1] as $template) { @@ -830,7 +828,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // RECURSIVE PROTECTION! BE CAREFUL HERE! if ((!isset($this->loadedRawData[$template])) && (!in_array($template, $this->loadedTemplates))) { // Debug message - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']:template=' . $template); + //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:template=' . $template); // Template not found, but maybe variable assigned? if ($this->getVariableIndex($template) !== false) { @@ -854,8 +852,8 @@ class BaseTemplateEngine extends BaseFrameworkSystem { array_push($this->rawTemplates, $template); } } - } // END - if - } // END - foreach + } + } // Restore the raw template data $this->setRawTemplateData($backup); @@ -868,12 +866,12 @@ 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); @@ -921,8 +919,8 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // Set the new raw data $this->setRawTemplateData($rawData); - } // END - if - } // END - foreach + } + } } /** @@ -952,8 +950,8 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // This template was never found. We silently ignore it unset($this->rawTemplates[$key]); } - } // END - foreach - } // END - if + } + } } /** @@ -965,21 +963,21 @@ class BaseTemplateEngine extends BaseFrameworkSystem { */ private function assignAllVariables (array $varMatches) { // Debug message - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']:varMatches()=' . count($varMatches)); + //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:varMatches()=' . count($varMatches)); // Search for all variables foreach ($varMatches[1] as $key => $var) { // Replace all dashes to underscores to match variables with configuration entries - $var = trim(self::convertDashesToUnderscores($var)); + $var = trim(StringUtils::convertDashesToUnderscores($var)); // Debug message - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']:key=' . $key . ',var=' . $var); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:key=' . $key . ',var=' . $var); // Detect leading equals 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) == '"')) { @@ -987,9 +985,9 @@ class BaseTemplateEngine extends BaseFrameworkSystem { $this->assignVariable($var, $varMatches[3][$key]); } elseif (!empty($varMatches[2][$key])) { // @TODO Non-string found so we need some deeper analysis... - ApplicationEntryPoint::app_exit('Deeper analysis not yet implemented!'); + ApplicationEntryPoint::exitApplication('Deeper analysis not yet implemented!'); } - } // END - foreach + } } /** @@ -1000,21 +998,21 @@ class BaseTemplateEngine extends BaseFrameworkSystem { */ private function compileRawTemplateData (array $templateMatches) { // Debug message - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']:loadedRawData()= ' .count($this->loadedRawData)); + //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:loadedRawData()= ' .count($this->loadedRawData)); // Are some code-templates found which we need to compile? if (count($this->loadedRawData) > 0) { // Then compile all! foreach ($this->loadedRawData as $template => $code) { // Debug message - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']:template=' . $template . ',code(' . strlen($code) . ')=' . $code); + //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:template=' . $template . ',code(' . strlen($code) . ')=' . $code); // Is this template already compiled? if (in_array($template, $this->compiledTemplates)) { // Then skip it - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']: Template ' . $template . ' already compiled. SKIPPED!'); + //* 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]); @@ -1023,19 +1021,19 @@ class BaseTemplateEngine extends BaseFrameworkSystem { if (($foundIndex !== false) && (isset($templateMatches[3][$foundIndex]))) { // Split it up with another reg. exp. into variable=value pairs preg_match_all($this->regExpVarValue, $templateMatches[3][$foundIndex], $varMatches); - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']:varMatches=' . print_r($varMatches, true)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:varMatches=' . print_r($varMatches, true)); // 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) ... + } } /** @@ -1059,18 +1057,18 @@ class BaseTemplateEngine extends BaseFrameworkSystem { private function finalizeVariableCompilation () { // Get the content $content = $this->getRawTemplateData(); - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']: content before=' . strlen($content) . ' (' . md5($content) . ')'); + //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: content before=' . strlen($content) . ' (' . md5($content) . ')'); // Do we have the stack? if (!$this->isVarStackSet('general')) { // Abort here silently // @TODO This silent abort should be logged, maybe. return; - } // END - if + } // Walk through all variables foreach ($this->getVarStack('general') as $currEntry) { - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']: name=' . $currEntry['name'] . ', value=
' . htmlentities($currEntry['value']) . '
'); + //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: name=' . $currEntry['name'] . ', value=
' . htmlentities($currEntry['value']) . '
'); // Replace all [$var] or {?$var?} with the content // @TODO Old behaviour, will become obsolete! $content = str_replace('$content[' . $currEntry['name'] . ']', $currEntry['value'], $content); @@ -1080,11 +1078,10 @@ 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[' . __METHOD__ . ':' . __LINE__ . ']: 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); } @@ -1095,9 +1092,9 @@ 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')); + $this->setTemplateType(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('html_template_type')); // Load the special template $this->loadTemplate($template); @@ -1109,17 +1106,17 @@ 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 EmptyVariableException If the variable name is left empty + * @throws InvalidArgumentException If the variable name is left empty */ - public final function assignVariable ($variableName, $value) { - // Replace all dashes to underscores to match variables with configuration entries - $variableName = trim(self::convertDashesToUnderscores($variableName)); - - // Empty variable found? + public final function assignVariable (string $variableName, $value) { + // Validate parameter if (empty($variableName)) { // Throw an exception - throw new EmptyVariableException(array($this, 'variableName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); - } // END - if + throw new InvalidArgumentException('Parameter "variableName" is empty'); + } + + // Replace all dashes to underscores to match variables with configuration entries + $variableName = trim(StringUtils::convertDashesToUnderscores($variableName)); // First search for the variable if it was already added $index = $this->getVariableIndex($variableName); @@ -1127,11 +1124,11 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // Was it found? if ($index === false) { // Add it to the stack - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']:ADD: ' . $variableName . '[' . gettype($value) . ']=' . $value); + //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:ADD: ' . $variableName . '[' . gettype($value) . ']=' . $value); $this->addVariable($variableName, $value); } elseif (!empty($value)) { // Modify the stack entry - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']:MOD: ' . $variableName . '[' . gettype($value) . ']=' . $value); + //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:MOD: ' . $variableName . '[' . gettype($value) . ']=' . $value); $this->modifyVariable($variableName, $value); } } @@ -1143,16 +1140,16 @@ 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); // Was it found? if ($index !== false) { // Remove this variable - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']:UNSET: variableGroup=' . $variableGroup . ',variableName=' . $variableName . ',index=' . $index); + //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:UNSET: variableGroup=' . $variableGroup . ',variableName=' . $variableName . ',index=' . $index); $this->unsetVariableStackOffset($index, $variableGroup); - } // END - if + } } /** @@ -1162,7 +1159,7 @@ 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(); @@ -1179,13 +1176,13 @@ 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(self::convertDashesToUnderscores($variableName)); + $variableName = trim(StringUtils::convertDashesToUnderscores($variableName)); // Sweet and simple... - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']: variableName=' . $variableName . ',getConfigEntry()=' . $this->getConfigInstance()->getConfigEntry($variableName)); - $this->assignVariable($variableName, $this->getConfigInstance()->getConfigEntry($variableName)); + //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: variableName=' . $variableName . ',getConfigEntry()=' . FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($variableName)); + $this->assignVariable($variableName, FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($variableName)); } /** @@ -1203,16 +1200,18 @@ class BaseTemplateEngine extends BaseFrameworkSystem { foreach ($variables as $name => $value) { // Set variable with name for 'config' group $this->assignVariable($name, $value); - } // END - foreach + } } /** * Assigns all the application data with template variables * - * @param $applicationInstance A manageable application instance * @return void */ - public function assignApplicationData (ManageableApplication $applicationInstance) { + public function assignApplicationData () { + // Get application instance + $applicationInstance = ApplicationHelper::getSelfInstance(); + // Get long name and assign it $this->assignVariable('app_full_name' , $applicationInstance->getAppName()); @@ -1233,9 +1232,9 @@ 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')); + $this->setTemplateType(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('code_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_template_type')); // Load the special template $this->loadTemplate($template); @@ -1248,9 +1247,9 @@ 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')); + $this->setTemplateType(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('email_template_type')); // Load the special template $this->loadTemplate($template); @@ -1267,9 +1266,9 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // Do we have the stack? if (!$this->isVarStackSet('general')) { // Abort here silently - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']: Aborted, variable stack general not found!'); + //* 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) { @@ -1277,21 +1276,21 @@ class BaseTemplateEngine extends BaseFrameworkSystem { $value = $this->compileRawCode($this->readVariable($currVariable['name']), true); // Debug message - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']: name=' . $currVariable['name'] . ',value=' . $value); + //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: name=' . $currVariable['name'] . ',value=' . $value); // Remove it from stack $this->removeVariable($currVariable['name'], 'general'); - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']: value='. $value . ',name=' . $currVariable['name'] . ',index=' . $index); + //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: value='. $value . ',name=' . $currVariable['name'] . ',index=' . $index); // Is it a configuration key? - if ($this->getConfigInstance()->isConfigurationEntrySet($value)) { + if (FrameworkBootstrap::getConfigurationInstance()->isConfigurationEntrySet($value)) { // The value itself is a configuration entry $this->assignConfigVariable($value); } else { // Re-assign the value directly $this->assignVariable($currVariable['name'], $value); } - } // END - foreach + } } /** @@ -1302,15 +1301,15 @@ class BaseTemplateEngine extends BaseFrameworkSystem { */ public final function compileVariables () { // Initialize the $content array - $validVar = $this->getConfigInstance()->getConfigEntry('tpl_valid_var'); - $dummy = array(); + $validVar = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('tpl_valid_var'); + $dummy = []; // Iterate through all general variables foreach ($this->getVarStack('general') as $currVariable) { // Transfer it's name/value combination to the $content array - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']:' . $currVariable['name'] . '=
' . htmlentities($currVariable['value']).'
'); + //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:' . $currVariable['name'] . '=
' . htmlentities($currVariable['value']).'
'); $dummy[$currVariable['name']] = $currVariable['value']; - }// END - if + } // Set the new variable (don't remove the second dollar!) $$validVar = $dummy; @@ -1347,7 +1346,7 @@ 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( @@ -1369,12 +1368,12 @@ 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(); @@ -1394,13 +1393,13 @@ class BaseTemplateEngine extends BaseFrameworkSystem { */ public function compileTemplate () { // Get code type to make things shorter - $codeType = $this->getConfigInstance()->getConfigEntry('code_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_template_type'); + $codeType = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('code_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_template_type'); // We will only work with template type "code" from configuration 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 + throw new UnexpectedTemplateTypeException(array($this, $this->getTemplateType(), FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('code_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_template_type')), self::EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED); + } // Get the raw data. $rawData = $this->getRawTemplateData(); @@ -1415,7 +1414,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { preg_match_all($this->regExpCodeTags, $rawData, $templateMatches); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']:templateMatches=' . print_r($templateMatches , true)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:templateMatches=' . print_r($templateMatches , true)); // Analyze the matches array if ((is_array($templateMatches)) && (count($templateMatches) == 4) && (count($templateMatches[0]) > 0)) { @@ -1437,8 +1436,8 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // Remove the raw template content as well $this->setRawTemplateData(''); - } // END - if - } // END - if($templateMatches ... + } + } } /** @@ -1447,15 +1446,15 @@ 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 - $className = self::convertToClassName($helperName) . 'ViewHelper'; + $className = StringUtils::convertToClassName($helperName) . 'ViewHelper'; // Generate new instance $this->helpers[$helperName] = ObjectFactory::createObjectByName($className); - } // END - if + } // Return the requested instance return $this->helpers[$helperName]; @@ -1479,24 +1478,24 @@ 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[' . __METHOD__ . ':' . __LINE__ . ']:rawCode=
' . htmlentities($rawCode) . '
'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:rawCode=
' . htmlentities($rawCode) . '
'); preg_match_all($this->regExpVarValue, $rawCode, $varMatches); // Compile all variables - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']:
' . print_r($varMatches, true) . '
'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:
' . print_r($varMatches, true) . '
'); foreach ($varMatches[0] as $match) { // Add variable tags around it $varCode = '{?' . $match . '?}'; // Debug message - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']:varCode=' . $varCode); + //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:varCode=' . $varCode); // Is the variable found in code? (safes some calls) if (strpos($rawCode, $varCode) !== false) { // Debug message - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']: match=' . $match . ',rawCode[' . gettype($rawCode) . ']=' . $rawCode); + //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: match=' . $match . ',rawCode[' . gettype($rawCode) . ']=' . $rawCode); // Use $match as new value or $value from read variable? if ($setMatchAsCode === true) { @@ -1509,11 +1508,11 @@ 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[' . __METHOD__ . ':' . __LINE__ . ']:rawCode=
' . htmlentities($rawCode) . '
'); + //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:rawCode=
' . htmlentities($rawCode) . '
'); return $rawCode; } @@ -1533,8 +1532,8 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * @param $newName New name of variable * @return void */ - public function renameVariable ($oldName, $newName) { - //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']: oldName=' . $oldName . ', newName=' . $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(); @@ -1545,41 +1544,14 @@ 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 ($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)); - - // 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)); - } // END - if - - // Parse the XML document - $parserInstance->parseXmlContent($content); - } - /** * Enables or disables language support * * @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; } /** @@ -1591,32 +1563,13 @@ class BaseTemplateEngine extends BaseFrameworkSystem { return $this->languageSupport; } - /** - * Enables or disables XML compacting - * - * @param $xmlCompacting New XML compacting setting - * @return void - */ - public final function enableXmlCompacting ($xmlCompacting = true) { - $this->xmlCompacting = (bool) $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 * * @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))); @@ -1629,8 +1582,8 @@ 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);