X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=framework%2Fmain%2Fclasses%2Ftemplate%2Fclass_BaseTemplateEngine.php;fp=framework%2Fmain%2Fclasses%2Ftemplate%2Fclass_BaseTemplateEngine.php;h=cebf170d3056a6e1279c54d971381853fb98922e;hp=cb0712578ad38c5e73e86b80dbf27cd034d45340;hb=146c8b3c929a1b0ab17d6605e5ae949ac44899c1;hpb=d5dc929cca6a35725ff7af3446e2764e6c739d81 diff --git a/framework/main/classes/template/class_BaseTemplateEngine.php b/framework/main/classes/template/class_BaseTemplateEngine.php index cb071257..cebf170d 100644 --- a/framework/main/classes/template/class_BaseTemplateEngine.php +++ b/framework/main/classes/template/class_BaseTemplateEngine.php @@ -3,6 +3,7 @@ namespace CoreFramework\Template\Engine; // Import framework stuff +use CoreFramework\Bootstrap\FrameworkBootstrap; use CoreFramework\Factory\ObjectFactory; use CoreFramework\Generic\EmptyVariableException; use CoreFramework\Manager\ManageableApplication; @@ -149,12 +150,12 @@ class BaseTemplateEngine extends BaseFrameworkSystem { /** * Language support is enabled by default */ - private $languageSupport = TRUE; + private $languageSupport = true; /** * XML compacting is disabled by default */ - private $xmlCompacting = FALSE; + private $xmlCompacting = false; // Exception codes for the template engine const EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED = 0x110; @@ -184,14 +185,14 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * * @param $variableName The variable we are looking for * @param $variableGroup Optional variable group to look in - * @return $index FALSE means not found, >=0 means found on a specific index + * @return $index false means not found, >=0 means found on a specific index */ private function getVariableIndex ($variableName, $variableGroup = NULL) { // Replace all dashes to underscores to match variables with configuration entries $variableName = trim(self::convertDashesToUnderscores($variableName)); // First everything is not found - $found = FALSE; + $found = false; // If the stack is NULL, use the current group if (is_null($variableGroup)) { @@ -279,7 +280,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { $found = $this->getVariableIndex($variableName, $variableGroup); // Is the variable found? - if ($found !== FALSE) { + if ($found !== false) { // Read it $content = $this->getVariableValue($variableGroup, $found); } // END - if @@ -330,13 +331,13 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * @param $add Whether add this group * @return void */ - public function setVariableGroup ($groupName, $add = TRUE) { + public function setVariableGroup ($groupName, $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)) { + if (($groupName != 'general') && ($add === true)) { $this->variableGroups[$groupName] = 'OK'; } // END - if } @@ -394,7 +395,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { $index = $this->getVariableIndex($variableName); // Is the variable set? - if ($index === FALSE) { + if ($index === false) { // Unset variables cannot be modified throw new NoVariableException(array($this, $variableName, $value), self::EXCEPTION_VARIABLE_IS_MISSING); } // END - if @@ -433,7 +434,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { $index = $this->getVariableIndex($variableName); // Is the variable set? - if ($index === FALSE) { + if ($index === false) { // Is the stack there? if (!isset($this->varStack[$variableGroup])) { // Then initialize it here @@ -778,7 +779,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { 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)); + //* 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)) { @@ -830,7 +831,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']:template=' . $template); // Template not found, but maybe variable assigned? - if ($this->getVariableIndex($template) !== FALSE) { + if ($this->getVariableIndex($template) !== false) { // Use that content here $this->loadedRawData[$template] = $this->readVariable($template); @@ -908,7 +909,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { $foundIndex = array_search($template, $templateMatches[1]); // Lookup the matching template replacement - if (($foundIndex !== FALSE) && (isset($templateMatches[0][$foundIndex]))) { + if (($foundIndex !== false) && (isset($templateMatches[0][$foundIndex]))) { // Get the current raw template $rawData = $this->getRawTemplateData(); @@ -1017,10 +1018,10 @@ class BaseTemplateEngine extends BaseFrameworkSystem { $foundIndex = array_search($template, $templateMatches[1]); // Lookup the matching variable data - if (($foundIndex !== FALSE) && (isset($templateMatches[3][$foundIndex]))) { + 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[' . __METHOD__ . ':' . __LINE__ . ']:varMatches=' . print_r($varMatches, true)); // Assign all variables $this->assignAllVariables($varMatches); @@ -1122,7 +1123,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { $index = $this->getVariableIndex($variableName); // Was it found? - if ($index === FALSE) { + if ($index === false) { // Add it to the stack //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']:ADD: ' . $variableName . '[' . gettype($value) . ']=' . $value); $this->addVariable($variableName, $value); @@ -1145,7 +1146,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { $index = $this->getVariableIndex($variableName, $variableGroup); // Was it found? - if ($index !== FALSE) { + if ($index !== false) { // Remove this variable //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']:UNSET: variableGroup=' . $variableGroup . ',variableName=' . $variableName . ',index=' . $index); $this->unsetVariableStackOffset($index, $variableGroup); @@ -1232,7 +1233,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { */ public function loadCodeTemplate ($template) { // Set template type - $this->setTemplateType($this->getConfigInstance()->getConfigEntry('code_' . self::getResponseTypeFromSystem() . '_template_type')); + $this->setTemplateType($this->getConfigInstance()->getConfigEntry('code_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_template_type')); // Load the special template $this->loadTemplate($template); @@ -1271,7 +1272,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // Iterate through all general variables foreach ($this->getVarStack('general') as $index => $currVariable) { // Compile the value - $value = $this->compileRawCode($this->readVariable($currVariable['name']), TRUE); + $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); @@ -1328,7 +1329,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { ); // This loop does remove the backslashes (\) in PHP parameters - while (strpos($eval, $this->codeBegin) !== FALSE) { + while (strpos($eval, $this->codeBegin) !== false) { // Get left part before "codeBegin)); @@ -1362,7 +1363,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { // Goes something wrong? if ((!isset($result)) || (empty($result))) { // Output eval command - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Failed eval() code:
%s
', $this->markupCode($eval, TRUE)), TRUE); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Failed eval() code:
%s
', $this->markupCode($eval, true)), true); // Output backtrace here $this->debugBackTrace(); @@ -1391,12 +1392,12 @@ class BaseTemplateEngine extends BaseFrameworkSystem { */ public function compileTemplate () { // Get code type to make things shorter - $codeType = $this->getConfigInstance()->getConfigEntry('code_' . self::getResponseTypeFromSystem() . '_template_type'); + $codeType = $this->getConfigInstance()->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_' . self::getResponseTypeFromSystem() . '_template_type')), self::EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED); + 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. @@ -1412,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[' . __METHOD__ . ':' . __LINE__ . ']:templateMatches=' . print_r($templateMatches , true)); // Analyze the matches array if ((is_array($templateMatches)) && (count($templateMatches) == 4) && (count($templateMatches[0]) > 0)) { @@ -1476,13 +1477,13 @@ 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 ($rawCode, $setMatchAsCode=false) { // Find the variables //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']: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[' . __METHOD__ . ':' . __LINE__ . ']:
' . print_r($varMatches, true) . '
'); foreach ($varMatches[0] as $match) { // Add variable tags around it $varCode = '{?' . $match . '?}'; @@ -1491,12 +1492,12 @@ class BaseTemplateEngine extends BaseFrameworkSystem { //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']:varCode=' . $varCode); // Is the variable found in code? (safes some calls) - if (strpos($rawCode, $varCode) !== FALSE) { + if (strpos($rawCode, $varCode) !== false) { // Debug message //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']: match=' . $match . ',rawCode[' . gettype($rawCode) . ']=' . $rawCode); // Use $match as new value or $value from read variable? - if ($setMatchAsCode === TRUE) { + if ($setMatchAsCode === true) { // Insert match $rawCode = str_replace($varCode, $match, $rawCode); } else { @@ -1575,7 +1576,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * @param $languageSupport New language support setting * @return void */ - public final function enableLanguageSupport ($languageSupport = TRUE) { + public final function enableLanguageSupport ($languageSupport = true) { $this->languageSupport = (bool) $languageSupport; } @@ -1594,7 +1595,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * @param $xmlCompacting New XML compacting setting * @return void */ - public final function enableXmlCompacting ($xmlCompacting = TRUE) { + public final function enableXmlCompacting ($xmlCompacting = true) { $this->xmlCompacting = (bool) $xmlCompacting; }