X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=framework%2Fmain%2Fclasses%2Ftemplate%2Fclass_BaseTemplateEngine.php;h=8c09dfbf91a01dfa65b5c601a73932a3500a3181;hb=035b3221bff7b542e264a9d0a4a6d086833487ef;hp=fd116e5cf166fa48a410e50b79ef68b541b09d78;hpb=c6edcfe27f630eb68192783b155795273da28c2d;p=core.git
diff --git a/framework/main/classes/template/class_BaseTemplateEngine.php b/framework/main/classes/template/class_BaseTemplateEngine.php
index fd116e5c..8c09dfbf 100644
--- a/framework/main/classes/template/class_BaseTemplateEngine.php
+++ b/framework/main/classes/template/class_BaseTemplateEngine.php
@@ -1,22 +1,30 @@
* @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
*
@@ -33,7 +41,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
@@ -77,24 +94,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
@@ -126,7 +143,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
/**
* Loaded helpers
*/
- private $helpers = array();
+ private $helpers = [];
/**
* Current variable group
@@ -136,7 +153,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
/**
* All template groups except "general"
*/
- private $variableGroups = array();
+ private $variableGroups = [];
/**
* Code begin
@@ -153,24 +170,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);
@@ -188,9 +194,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;
@@ -200,7 +206,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)) {
@@ -213,9 +219,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;
@@ -227,7 +233,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]);
@@ -241,7 +247,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];
}
@@ -252,7 +258,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;
}
@@ -263,9 +269,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;
@@ -275,7 +281,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);
@@ -284,7 +290,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);
@@ -298,7 +304,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');
@@ -313,13 +319,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;
@@ -332,7 +338,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;
@@ -340,7 +346,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
// Skip group 'general'
if (($groupName != 'general') && ($add === true)) {
$this->variableGroups[$groupName] = 'OK';
- } // END - if
+ }
}
@@ -351,9 +357,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);
@@ -375,7 +381,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'];
}
@@ -388,9 +394,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);
@@ -399,7 +405,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);
@@ -413,7 +419,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;
}
@@ -427,9 +433,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);
@@ -439,8 +445,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));
@@ -458,9 +464,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(
@@ -479,8 +485,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;
}
/**
@@ -493,17 +499,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
*/
@@ -517,9 +523,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;
}
/**
@@ -549,9 +555,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;
}
/**
@@ -561,9 +567,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;
}
/**
@@ -595,9 +601,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;
}
/**
@@ -607,18 +613,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]);
@@ -630,11 +636,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;
}
/**
@@ -643,19 +649,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;
}
/**
@@ -664,26 +671,26 @@ 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;
}
/**
* Private loader for all template types
*
- * @param $template The template we shall load
+ * @param $templateName The template we shall load
* @param $extOther An other extension to use
* @return void
* @throws FileNotFoundException If the template was not found
*/
- protected function loadTemplate ($template, $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;
}
/*
@@ -691,30 +698,30 @@ 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',
- $this->getConfigInstance()->getConfigEntry('application_base_path'),
+ $fileInstance = new SplFileInfo(sprintf('%s%s%s%s%s%s',
$this->getTemplateBasePath(),
$this->getGenericBasePath(),
$this->getTemplateType(),
- (string) $template,
+ 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();
// Try it again...
- $this->loadTemplate($template, $ext);
+ $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);
}
}
@@ -723,38 +730,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') {
@@ -772,16 +775,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
@@ -793,9 +791,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
+ }
+ }
+ }
}
/**
@@ -819,9 +817,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) {
@@ -829,7 +827,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) {
@@ -853,8 +851,8 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
array_push($this->rawTemplates, $template);
}
}
- } // END - if
- } // END - foreach
+ }
+ }
// Restore the raw template data
$this->setRawTemplateData($backup);
@@ -867,12 +865,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);
@@ -920,8 +918,8 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
// Set the new raw data
$this->setRawTemplateData($rawData);
- } // END - if
- } // END - foreach
+ }
+ }
}
/**
@@ -951,8 +949,8 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
// This template was never found. We silently ignore it
unset($this->rawTemplates[$key]);
}
- } // END - foreach
- } // END - if
+ }
+ }
}
/**
@@ -964,21 +962,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) == '"')) {
@@ -986,9 +984,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
+ }
}
/**
@@ -999,21 +997,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]);
@@ -1022,19 +1020,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) ...
+ }
}
/**
@@ -1058,18 +1056,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);
@@ -1079,11 +1077,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);
}
@@ -1094,9 +1091,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);
@@ -1108,17 +1105,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);
@@ -1126,11 +1123,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);
}
}
@@ -1142,16 +1139,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
+ }
}
/**
@@ -1161,7 +1158,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();
@@ -1178,13 +1175,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));
}
/**
@@ -1202,16 +1199,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 = GenericRegistry::getRegistry()->getInstance('application');
+
// Get long name and assign it
$this->assignVariable('app_full_name' , $applicationInstance->getAppName());
@@ -1232,9 +1231,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);
@@ -1247,9 +1246,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);
@@ -1266,9 +1265,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) {
@@ -1276,21 +1275,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
+ }
}
/**
@@ -1301,15 +1300,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;
@@ -1346,7 +1345,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(
@@ -1368,12 +1367,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();
@@ -1393,13 +1392,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();
@@ -1414,7 +1413,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)) {
@@ -1436,8 +1435,8 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
// Remove the raw template content as well
$this->setRawTemplateData('');
- } // END - if
- } // END - if($templateMatches ...
+ }
+ }
}
/**
@@ -1446,15 +1445,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];
@@ -1478,24 +1477,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) {
@@ -1508,11 +1507,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;
}
@@ -1532,8 +1531,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();
@@ -1544,41 +1543,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;
}
/**
@@ -1590,32 +1562,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)));
@@ -1628,8 +1581,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);