Moved config loading code inside main class, the compiled template now

simply calls that method.
This commit is contained in:
andrey
2001-06-19 15:30:29 +00:00
parent 911da5cf03
commit 73b049acb7
5 changed files with 81 additions and 60 deletions

View File

@@ -526,7 +526,7 @@ class Smarty
if ($this->show_info_header) {
$info_header = '<!-- Smarty '.$this->_version.' '.strftime("%Y-%m-%d %H:%M:%S %Z").' -->'."\n\n";
} else {
$info_header = "";
$info_header = '';
}
// if we just need to display the results, don't perform output
@@ -756,6 +756,33 @@ class Smarty
array_shift($this->_config);
}
/*======================================================================*\
Function: _config_load
Purpose: load configuration values
\*======================================================================*/
function _config_load($file, $section, $scope)
{
$this->_config[0] = array_merge($this->_config[0], $this->_conf_obj->get($file));
if ($scope == 'parent') {
if (count($this->_config) > 0)
$this->_config[1] = array_merge($this->_config[1], $this->_conf_obj->get($file));
} else if ($scope == 'global')
for ($i = 1; $i < count($this->_config); $i++)
$this->_config[$i] = array_merge($this->_config[$i], $this->_conf_obj->get($file));
if (!empty($section)) {
$this->_config[0] = array_merge($this->_config[0], $this->_conf_obj->get($file, $section));
if ($scope == 'parent') {
if (count($this->_config) > 0)
$this->_config[1] = array_merge($this->_config[1], $this->_conf_obj->get($file, $section));
} else if ($scope == 'global')
for ($i = 1; $i < count($this->_config); $i++)
$this->_config[$i] = array_merge($this->_config[$i], $this->_conf_obj->get($file, $section));
}
}
/*======================================================================*\
Function: _process_cached_inserts
Purpose: Replace cached inserts with the actual results

View File

@@ -54,7 +54,7 @@ class Smarty_Compiler extends Smarty {
\*======================================================================*/
function _compile_file($tpl_file, $template_source, &$template_compiled)
{
if($this->security) {
if ($this->security) {
// do not allow php syntax to be executed unless specified
if ($this->php_handling == SMARTY_PHP_ALLOW &&
!$this->security_settings['PHP_HANDLING']) {
@@ -347,12 +347,15 @@ class Smarty_Compiler extends Smarty {
$this->_syntax_error("missing 'file' attribute in config_load tag");
}
if (empty($attrs['section'])) {
$attrs['section'] = 'null';
}
$scope = $this->_dequote($attrs['scope']);
if (!empty($scope)) {
if ($scope != 'local' &&
$scope != 'parent' &&
$scope != 'global') {
var_dump($scope);
$this->_syntax_error("invalid 'scope' attribute value");
}
} else {
@@ -362,27 +365,7 @@ class Smarty_Compiler extends Smarty {
$scope = 'local';
}
$output = "<?php\n" .
"\$this->_config[0] = array_merge(\$this->_config[0], \$this->_conf_obj->get(".$attrs['file']."));\n";
if ($scope == 'parent')
$output .= "if (count(\$this->_config) > 0)\n" .
" \$this->_config[1] = array_merge(\$this->_config[1], \$this->_conf_obj->get(".$attrs['file']."));\n";
else if ($scope == 'global')
$output .= "for (\$this->_i = 1; \$this->_i < count(\$this->_config); \$this->_i++)\n" .
" \$this->_config[\$this->_i] = array_merge(\$this->_config[\$this->_i], \$this->_conf_obj->get(".$attrs['file']."));\n";
$dq_section = $this->_dequote($attrs['section']);
if (!empty($dq_section)) {
$output .= "\$this->_config[0] = array_merge(\$this->_config[0], \$this->_conf_obj->get(".$attrs['file'].", ".$attrs['section']."));\n";
if ($scope == 'parent')
$output .= "if (count(\$this->_config) > 0)\n" .
" \$this->_config[1] = array_merge(\$this->_config[1], \$this->_conf_obj->get(".$attrs['file'].", ".$attrs['section']."));\n";
else if ($scope == 'global')
$output .= "for (\$this->_i = 1; \$this->_i < count(\$this->_config); \$this->_i++)\n" .
" \$this->_config[\$this->_i] = array_merge(\$this->_config[\$this->_i], \$this->_conf_obj->get(".$attrs['file'].", ".$attrs['section']."));\n";
}
$output .= '?>';
$output = '<?php $this->_config_load(' . $attrs['file'] . ', ' . $attrs['section'] . ", '$scope'); ?>";
return $output;
}

1
TODO
View File

@@ -7,3 +7,4 @@
* think about passing default structures to includes, i.e. {include
default=$foo}, then using $bar in included template, instead of $foo.bar
* support implementations of prefiltes, mods, and others as class methods.
* possibly implement default modifiers that apply to variables upon display

View File

@@ -526,7 +526,7 @@ class Smarty
if ($this->show_info_header) {
$info_header = '<!-- Smarty '.$this->_version.' '.strftime("%Y-%m-%d %H:%M:%S %Z").' -->'."\n\n";
} else {
$info_header = "";
$info_header = '';
}
// if we just need to display the results, don't perform output
@@ -756,6 +756,33 @@ class Smarty
array_shift($this->_config);
}
/*======================================================================*\
Function: _config_load
Purpose: load configuration values
\*======================================================================*/
function _config_load($file, $section, $scope)
{
$this->_config[0] = array_merge($this->_config[0], $this->_conf_obj->get($file));
if ($scope == 'parent') {
if (count($this->_config) > 0)
$this->_config[1] = array_merge($this->_config[1], $this->_conf_obj->get($file));
} else if ($scope == 'global')
for ($i = 1; $i < count($this->_config); $i++)
$this->_config[$i] = array_merge($this->_config[$i], $this->_conf_obj->get($file));
if (!empty($section)) {
$this->_config[0] = array_merge($this->_config[0], $this->_conf_obj->get($file, $section));
if ($scope == 'parent') {
if (count($this->_config) > 0)
$this->_config[1] = array_merge($this->_config[1], $this->_conf_obj->get($file, $section));
} else if ($scope == 'global')
for ($i = 1; $i < count($this->_config); $i++)
$this->_config[$i] = array_merge($this->_config[$i], $this->_conf_obj->get($file, $section));
}
}
/*======================================================================*\
Function: _process_cached_inserts
Purpose: Replace cached inserts with the actual results

View File

@@ -54,7 +54,7 @@ class Smarty_Compiler extends Smarty {
\*======================================================================*/
function _compile_file($tpl_file, $template_source, &$template_compiled)
{
if($this->security) {
if ($this->security) {
// do not allow php syntax to be executed unless specified
if ($this->php_handling == SMARTY_PHP_ALLOW &&
!$this->security_settings['PHP_HANDLING']) {
@@ -347,12 +347,15 @@ class Smarty_Compiler extends Smarty {
$this->_syntax_error("missing 'file' attribute in config_load tag");
}
if (empty($attrs['section'])) {
$attrs['section'] = 'null';
}
$scope = $this->_dequote($attrs['scope']);
if (!empty($scope)) {
if ($scope != 'local' &&
$scope != 'parent' &&
$scope != 'global') {
var_dump($scope);
$this->_syntax_error("invalid 'scope' attribute value");
}
} else {
@@ -362,27 +365,7 @@ class Smarty_Compiler extends Smarty {
$scope = 'local';
}
$output = "<?php\n" .
"\$this->_config[0] = array_merge(\$this->_config[0], \$this->_conf_obj->get(".$attrs['file']."));\n";
if ($scope == 'parent')
$output .= "if (count(\$this->_config) > 0)\n" .
" \$this->_config[1] = array_merge(\$this->_config[1], \$this->_conf_obj->get(".$attrs['file']."));\n";
else if ($scope == 'global')
$output .= "for (\$this->_i = 1; \$this->_i < count(\$this->_config); \$this->_i++)\n" .
" \$this->_config[\$this->_i] = array_merge(\$this->_config[\$this->_i], \$this->_conf_obj->get(".$attrs['file']."));\n";
$dq_section = $this->_dequote($attrs['section']);
if (!empty($dq_section)) {
$output .= "\$this->_config[0] = array_merge(\$this->_config[0], \$this->_conf_obj->get(".$attrs['file'].", ".$attrs['section']."));\n";
if ($scope == 'parent')
$output .= "if (count(\$this->_config) > 0)\n" .
" \$this->_config[1] = array_merge(\$this->_config[1], \$this->_conf_obj->get(".$attrs['file'].", ".$attrs['section']."));\n";
else if ($scope == 'global')
$output .= "for (\$this->_i = 1; \$this->_i < count(\$this->_config); \$this->_i++)\n" .
" \$this->_config[\$this->_i] = array_merge(\$this->_config[\$this->_i], \$this->_conf_obj->get(".$attrs['file'].", ".$attrs['section']."));\n";
}
$output .= '?>';
$output = '<?php $this->_config_load(' . $attrs['file'] . ', ' . $attrs['section'] . ", '$scope'); ?>";
return $output;
}