use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint;
use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
+use Org\Mxchange\CoreFramework\Handler\Stream\IoHandler;
use Org\Mxchange\CoreFramework\Filesystem\FileNotFoundException;
use Org\Mxchange\CoreFramework\Generic\NullPointerException;
use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
abstract class BaseTemplateEngine extends BaseFrameworkSystem {
+ /**
+ * The file I/O instance for the template loader
+ */
+ private $fileIoInstance = NULL;
+
/**
* The local path name where all templates and sub folders for special
* templates are stored. We will internally determine the language plus
* @param $variableGroup Optional variable group to look in
* @return $index false means not found, >=0 means found on a specific index
*/
- private function getVariableIndex ($variableName, $variableGroup = NULL) {
+ private function getVariableIndex (string $variableName, string $variableGroup = NULL) {
// Replace all dashes to underscores to match variables with configuration entries
$variableName = trim(StringUtils::convertDashesToUnderscores($variableName));
// 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)) {
//* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(__METHOD__.':FOUND!');
$found = $index;
break;
- } // END - if
- } // END - foreach
- } // END - if
+ }
+ }
+ }
// Return the current position
return $found;
* @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]);
* @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];
}
* @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;
}
* @param $variableGroup Optional variable group to look in
* @return $content Content of the variable or null if not found
*/
- protected function readVariable ($variableName, $variableGroup = NULL) {
+ protected function readVariable (string $variableName, string $variableGroup = NULL) {
// Replace all dashes to underscores to match variables with configuration entries
$variableName = trim(StringUtils::convertDashesToUnderscores($variableName));
// 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);
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);
* @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');
if ($this->isVarStackSet($this->currGroup)) {
// Then use it
$result = $this->getVarStack($this->currGroup);
- } // END - if
+ }
// Return result
return $result;
* @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;
// Skip group 'general'
if (($groupName != 'general') && ($add === true)) {
$this->variableGroups[$groupName] = 'OK';
- } // END - if
+ }
}
* @param $value Value to store in variable
* @return void
*/
- public function addGroupVariable ($variableName, $value) {
+ public function addGroupVariable (string $variableName, $value) {
// Replace all dashes to underscores to match variables with configuration entries
$variableName = trim(StringUtils::convertDashesToUnderscores($variableName));
* @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'];
}
* @return void
* @throws NoVariableException If the given variable is not found
*/
- private function modifyVariable ($variableName, $value) {
+ private function modifyVariable (string $variableName, $value) {
// Replace all dashes to underscores to match variables with configuration entries
$variableName = trim(StringUtils::convertDashesToUnderscores($variableName));
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);
* @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;
}
* @param $value Value to set
* @return void
*/
- protected function setVariable ($variableGroup, $variableName, $value) {
+ protected function setVariable (string $variableGroup, string $variableName, $value) {
// Replace all dashes to underscores to match variables with configuration entries
$variableName = trim(StringUtils::convertDashesToUnderscores($variableName));
if (!isset($this->varStack[$variableGroup])) {
// Then initialize it here
$this->varStack[$variableGroup] = array();
- } // END - if
+ }
// Not found, add it
array_push($this->varStack[$variableGroup], $this->generateVariableArray($variableName, $value));
* @param $value Value to set
* @return $varData Variable data array
*/
- private function generateVariableArray ($variableName, $value) {
+ private function generateVariableArray (string $variableName, $value) {
// Replace all dashes to underscores to match variables with configuration entries
$variableName = trim(StringUtils::convertDashesToUnderscores($variableName));
* @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;
}
/**
* @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;
}
/**
* templates
* @return void
*/
- protected final function setRawTemplateExtension ($templateExtension) {
+ protected final function setRawTemplateExtension (string $templateExtension) {
// And set it
- $this->templateExtension = (string) $templateExtension;
+ $this->templateExtension = $templateExtension;
}
/**
* templates
* @return void
*/
- protected final function setCodeTemplateExtension ($codeExtension) {
+ protected final function setCodeTemplateExtension (string $codeExtension) {
// And set it
- $this->codeExtension = (string) $codeExtension;
+ $this->codeExtension = $codeExtension;
}
/**
* templates
* @return void
*/
- protected final function setCompileOutputPath ($compileOutputPath) {
+ protected final function setCompileOutputPath (string $compileOutputPath) {
// And set it
- $this->compileOutputPath = (string) $compileOutputPath;
+ $this->compileOutputPath = $compileOutputPath;
}
/**
* @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]);
* @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;
}
/**
/**
* Private setter for compiled templates
*
+ * @param $compiledData Compiled template data
* @return void
*/
- private final function setCompiledData ($compiledData) {
+ private final function setCompiledData (string $compiledData) {
// And store it in this class
//* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: ' . strlen($compiledData) . ' Bytes set.');
- $this->compiledData = (string) $compiledData;
+ $this->compiledData = $compiledData;
}
/**
* @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;
}
/*
* @return void
*/
private function loadRawTemplateData (SplFileInfo $fileInstance) {
- // Some debug code to look on the file which is being loaded
- //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: fileInstance=' . $fileInstance);
-
// Load the raw template
+ //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: fileInstance=' . $fileInstance);
$rawTemplateData = $this->getFileIoInstance()->loadFileContents($fileInstance);
// Store the template's contents into this class
* Try to assign an extracted template variable as a "content" or 'config'
* variable.
*
- * @param $variableName The variable's name (shall be content or config)
+ * @param $variableName The variable's name (shall be content or config)
* by default
* @param $variableName The variable we want to assign
* @return void
*/
- private function assignTemplateVariable ($variableName, $var) {
+ private function assignTemplateVariable (string $variableName, $var) {
// Replace all dashes to underscores to match variables with configuration entries
+ //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: variableName=' . $variableName . ',var=' . $var);
$variableName = trim(StringUtils::convertDashesToUnderscores($variableName));
- // Debug message
- //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: variableName=' . $variableName . ',variableName=' . $variableName);
-
// Is it not a config variable?
if ($variableName != 'config') {
// Regular template variables
* @param $rawData The raw template data we shall analyze
* @return void
*/
- private function extractVariablesFromRawData ($rawData) {
- // Cast to string
- $rawData = (string) $rawData;
-
+ private function extractVariablesFromRawData (string $rawData) {
// Search for variables
- preg_match_all('/\$(\w+)(\[(\w+)\])?/', $rawData, $variableMatches);
-
- // Debug message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:rawData(' . strlen($rawData) . ')=' . $rawData . ',variableMatches=' . print_r($variableMatches, true));
+ preg_match_all('/\$(\w+)(\[(\w+)\])?/', $rawData, $variableMatches);
// Did we find some variables?
if ((is_array($variableMatches)) && (count($variableMatches) == 4) && (count($variableMatches[0]) > 0)) {
if (!empty($var)) {
// Try to assign it, empty strings are being ignored
$this->assignTemplateVariable($variableName, $var);
- } // END - if
- } // END - foreach
- } // END - if
+ }
+ }
+ }
}
/**
// Initialize both
$this->loadedRawData = array();
$this->rawTemplates = array();
- } // END - if
+ }
// Load all requested templates
foreach ($templateMatches[1] as $template) {
array_push($this->rawTemplates, $template);
}
}
- } // END - if
- } // END - foreach
+ }
+ }
// Restore the raw template data
$this->setRawTemplateData($backup);
* @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);
// Set the new raw data
$this->setRawTemplateData($rawData);
- } // END - if
- } // END - foreach
+ }
+ }
}
/**
// This template was never found. We silently ignore it
unset($this->rawTemplates[$key]);
}
- } // END - foreach
- } // END - if
+ }
+ }
}
/**
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) == '"')) {
// @TODO Non-string found so we need some deeper analysis...
ApplicationEntryPoint::exitApplication('Deeper analysis not yet implemented!');
}
- } // END - foreach
+ }
}
/**
// Then skip it
//* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: Template ' . $template . ' already compiled. SKIPPED!');
continue;
- } // END - if
+ }
// Search for the template
$foundIndex = array_search($template, $templateMatches[1]);
// 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) ...
+ }
}
/**
// Abort here silently
// @TODO This silent abort should be logged, maybe.
return;
- } // END - if
+ }
// Walk through all variables
foreach ($this->getVarStack('general') as $currEntry) {
// The new behaviour
$content = str_replace('{?' . $currEntry['name'] . '?}', $currEntry['value'], $content);
- } // END - for
-
- //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: content after=' . strlen($content) . ' (' . md5($content) . ')');
+ }
// Set the content back
+ //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: content after=' . strlen($content) . ' (' . md5($content) . ')');
$this->setRawTemplateData($content);
}
* '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'));
* @param $variableName The variable we are looking for
* @param $value The value we want to store in the variable
* @return void
- * @throws NullPointerException If $variableName is NULL
* @throws InvalidArgumentException If the variable name is left empty
*/
- public final function assignVariable ($variableName, $value) {
+ public final function assignVariable (string $variableName, $value) {
// Validate parameter
- if (is_null($variableName)) {
- // Throw NPE
- throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
- } elseif (empty($variableName)) {
+ if (empty($variableName)) {
// Throw an exception
throw new InvalidArgumentException('Parameter "variableName" is empty');
}
* @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);
// Remove this variable
//* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:UNSET: variableGroup=' . $variableGroup . ',variableName=' . $variableName . ',index=' . $index);
$this->unsetVariableStackOffset($index, $variableGroup);
- } // END - if
+ }
}
/**
* @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();
* @param $variableName The configuration variable we want to assign
* @return void
*/
- public function assignConfigVariable ($variableName) {
+ public function assignConfigVariable (string $variableName) {
// Replace all dashes to underscores to match variables with configuration entries
$variableName = trim(StringUtils::convertDashesToUnderscores($variableName));
foreach ($variables as $name => $value) {
// Set variable with name for 'config' group
$this->assignVariable($name, $value);
- } // END - foreach
+ }
}
/**
* 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'));
* 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'));
// Abort here silently
//* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: Aborted, variable stack general not found!');
return;
- } // END - if
+ }
// Iterate through all general variables
foreach ($this->getVarStack('general') as $index => $currVariable) {
// Re-assign the value directly
$this->assignVariable($currVariable['name'], $value);
}
- } // END - foreach
+ }
}
/**
// Transfer it's name/value combination to the $content array
//* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:' . $currVariable['name'] . '=<pre>' . htmlentities($currVariable['value']).'</pre>');
$dummy[$currVariable['name']] = $currVariable['value'];
- }// END - if
+ }
// Set the new variable (don't remove the second dollar!)
$$validVar = $dummy;
// And put all together
$eval = sprintf('%s<%%php %s %%>%s', $evalLeft, $evalMiddle, $evalRight);
- } // END - while
+ }
// Prepare PHP code for eval() command
$eval = str_replace(
// Output backtrace here
$this->debugBackTrace();
- } // END - if
+ }
// Set raw template data
$this->setRawTemplateData($result);
$cnt++;
- } // END - while
+ }
// Final variable assignment
$this->finalizeVariableCompilation();
if (substr($this->getTemplateType(), 0, strlen($codeType)) != $codeType) {
// Abort here
throw new UnexpectedTemplateTypeException(array($this, $this->getTemplateType(), $this->getConfigInstance()->getConfigEntry('code_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_template_type')), self::EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED);
- } // END - if
+ }
// Get the raw data.
$rawData = $this->getRawTemplateData();
// Remove the raw template content as well
$this->setRawTemplateData('');
- } // END - if
- } // END - if($templateMatches ...
+ }
+ }
}
/**
* @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
// Generate new instance
$this->helpers[$helperName] = ObjectFactory::createObjectByName($className);
- } // END - if
+ }
// Return the requested instance
return $this->helpers[$helperName];
* @param $setMatchAsCode Sets $match if readVariable() returns empty result
* @return $rawCode Compile code with inserted variable value
*/
- public function compileRawCode ($rawCode, $setMatchAsCode=false) {
+ public function compileRawCode (string $rawCode, bool $setMatchAsCode = false) {
// Find the variables
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:rawCode=<pre>' . htmlentities($rawCode) . '</pre>');
preg_match_all($this->regExpVarValue, $rawCode, $varMatches);
// Insert value
$rawCode = str_replace($varCode, $value, $rawCode);
}
- } // END - if
- } // END - foreach
+ }
+ }
// Return the compiled data
//* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE:rawCode=<pre>' . htmlentities($rawCode) . '</pre>');
* @param $newName New name of variable
* @return void
*/
- public function renameVariable ($oldName, $newName) {
+ public function renameVariable (string $oldName, string $newName) {
//* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE: oldName=' . $oldName . ', newName=' . $newName);
// Get raw template code
$rawData = $this->getRawTemplateData();
* @return void
* @throws XmlParserException If an XML error was found
*/
- public function renderXmlContent ($content = NULL) {
+ public function renderXmlContent (string $content = NULL) {
// Is the content set?
if (is_null($content)) {
// Get current content
$content = $this->getRawTemplateData();
- } // END - if
+ }
// Get a XmlParser instance
$parserInstance = ObjectFactory::createObjectByConfiguredName('xml_parser_class', array($this));
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);
* @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;
}
/**
* @param $xmlCompacting New XML compacting setting
* @return void
*/
- public final function enableXmlCompacting ($xmlCompacting = true) {
- $this->xmlCompacting = (bool) $xmlCompacting;
+ public final function enableXmlCompacting (bool $xmlCompacting = true) {
+ $this->xmlCompacting = $xmlCompacting;
}
/**
return $this->xmlCompacting;
}
+ /**
+ * Private getter for file IO instance
+ *
+ * @return $fileIoInstance An instance to the file I/O sub-system
+ */
+ protected final function getFileIoInstance () {
+ return $this->fileIoInstance;
+ }
+
+ /**
+ * Setter for file I/O instance
+ *
+ * @param $fileIoInstance An instance to the file I/O sub-system
+ * @return void
+ */
+ public final function setFileIoInstance (IoHandler $fileIoInstance) {
+ $this->fileIoInstance = $fileIoInstance;
+ }
+
/**
* Removes all commentd, tabs and new-line characters to compact the content
*
* @param $uncompactedContent The uncompacted content
* @return $compactedContent The compacted content
*/
- public function compactContent ($uncompactedContent) {
+ public function compactContent (string $uncompactedContent) {
// First, remove all tab/new-line/revert characters
$compactedContent = str_replace(chr(9), '', str_replace(chr(10), '', str_replace(chr(13), '', $uncompactedContent)));
foreach ($matches[0] as $match) {
// Remove the match
$compactedContent = str_replace($match, '', $compactedContent);
- } // END - foreach
- } // END - if
+ }
+ }
// Set the content again
$this->setRawTemplateData($compactedContent);