mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 02:14:26 +02:00
Fix configfile tests
This commit is contained in:
@@ -140,8 +140,8 @@ class Configfile extends BaseCompiler {
|
|||||||
date("Y-m-d H:i:s"),
|
date("Y-m-d H:i:s"),
|
||||||
str_replace('*/', '* /', $this->template->source->filepath)
|
str_replace('*/', '* /', $this->template->source->filepath)
|
||||||
);
|
);
|
||||||
$code = '<?php $_smarty_tpl->assignConfigVars(' .
|
$code = '<?php $_smarty_tpl->parent->assignConfigVars(' .
|
||||||
var_export($this->config_data, true) . '); ?>';
|
var_export($this->config_data, true) . ', $_smarty_tpl->getValue("sections")); ?>';
|
||||||
return $template_header . $this->template->createCodeFrame($code);
|
return $template_header . $this->template->createCodeFrame($code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
63
src/Data.php
63
src/Data.php
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace Smarty;
|
namespace Smarty;
|
||||||
|
|
||||||
|
use Smarty\Template\Config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty Internal Plugin Data
|
* Smarty Internal Plugin Data
|
||||||
* This file contains the basic properties and methods for holding config and template variables
|
* This file contains the basic properties and methods for holding config and template variables
|
||||||
@@ -247,27 +249,24 @@ abstract class Data
|
|||||||
*
|
*
|
||||||
* @param array $new_config_vars
|
* @param array $new_config_vars
|
||||||
*/
|
*/
|
||||||
public function assignConfigVars($new_config_vars) {
|
public function assignConfigVars($new_config_vars, array $sections = []) {
|
||||||
|
|
||||||
// copy global config vars
|
// copy global config vars
|
||||||
foreach ($new_config_vars['vars'] as $variable => $value) {
|
foreach ($new_config_vars['vars'] as $variable => $value) {
|
||||||
if ($this->smarty->config_overwrite || !isset($this->config_vars[$variable])) {
|
if ($this->_getSmartyObj()->config_overwrite || !isset($this->config_vars[$variable])) {
|
||||||
$this->config_vars[$variable] = $value;
|
$this->config_vars[$variable] = $value;
|
||||||
} else {
|
} else {
|
||||||
$this->config_vars[$variable] = array_merge((array)$this->config_vars[$variable], (array)$value);
|
$this->config_vars[$variable] = array_merge((array)$this->config_vars[$variable], (array)$value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// scan sections
|
|
||||||
$sections = $this->source->config_sections;
|
foreach ($sections as $tpl_section) {
|
||||||
if (!empty($sections)) {
|
if (isset($new_config_vars['sections'][$tpl_section])) {
|
||||||
foreach ((array)$sections as $tpl_section) {
|
foreach ($new_config_vars['sections'][$tpl_section]['vars'] as $variable => $value) {
|
||||||
if (isset($new_config_vars['sections'][$tpl_section])) {
|
if ($this->_getSmartyObj()->config_overwrite || !isset($this->config_vars[$variable])) {
|
||||||
foreach ($new_config_vars['sections'][$tpl_section]['vars'] as $variable => $value) {
|
$this->config_vars[$variable] = $value;
|
||||||
if ($this->smarty->config_overwrite || !isset($this->config_vars[$variable])) {
|
} else {
|
||||||
$this->config_vars[$variable] = $value;
|
$this->config_vars[$variable] = array_merge((array)$this->config_vars[$variable], (array)$value);
|
||||||
} else {
|
|
||||||
$this->config_vars[$variable] = array_merge((array)$this->config_vars[$variable], (array)$value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -384,25 +383,6 @@ abstract class Data
|
|||||||
return array_merge($this->parent ? $this->parent->getConfigVars() : [], $this->config_vars);
|
return array_merge($this->parent ? $this->parent->getConfigVars() : [], $this->config_vars);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* load a config file, optionally load just selected sections
|
|
||||||
*
|
|
||||||
* @param string $config_file filename
|
|
||||||
* @param mixed $sections array of section names, single
|
|
||||||
* section or null
|
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
* @throws \Exception
|
|
||||||
*@api Smarty::configLoad()
|
|
||||||
* @link https://www.smarty.net/docs/en/api.config.load.tpl
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function configLoad($config_file, $sections = null)
|
|
||||||
{
|
|
||||||
$this->_loadConfigfile($config_file, $sections);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* load a config file, optionally load just selected sections
|
* load a config file, optionally load just selected sections
|
||||||
*
|
*
|
||||||
@@ -410,23 +390,22 @@ abstract class Data
|
|||||||
* @param mixed $sections array of section names, single
|
* @param mixed $sections array of section names, single
|
||||||
* section or null
|
* section or null
|
||||||
|
|
||||||
* @returns Template
|
* @returns $this
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
* @link https://www.smarty.net/docs/en/api.config.load.tpl
|
* @link https://www.smarty.net/docs/en/api.config.load.tpl
|
||||||
*
|
*
|
||||||
* @api Smarty::configLoad()
|
* @api Smarty::configLoad()
|
||||||
*/
|
*/
|
||||||
protected function _loadConfigfile($config_file, $sections = null)
|
public function configLoad($config_file, $sections = null)
|
||||||
{
|
{
|
||||||
$smarty = $this->_getSmartyObj();
|
$smarty = $this->_getSmartyObj();
|
||||||
|
$template = new Template($config_file, $smarty, $this, null, null, null, null, true);
|
||||||
$confObj = new Template($config_file, $smarty, $this, null, null, null, null, true);
|
$template->caching = Smarty::CACHING_OFF;
|
||||||
$confObj->caching = Smarty::CACHING_OFF;
|
$template->assign('sections', (array) $sections ?? []);
|
||||||
$confObj->source->config_sections = $sections;
|
// trigger a call to $this->assignConfigVars
|
||||||
$confObj->compiled = \Smarty\Template\Compiled::load($confObj);
|
$template->compiled = \Smarty\Template\Compiled::load($template);
|
||||||
$confObj->compiled->render($confObj);
|
$template->compiled->render($template);
|
||||||
return $confObj;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -693,9 +693,9 @@ class Template extends TemplateBase {
|
|||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
protected function _loadConfigfile($config_file, $sections = null)
|
public function configLoad($config_file, $sections = null)
|
||||||
{
|
{
|
||||||
$confObj = parent::_loadConfigfile($config_file, $sections);
|
$confObj = parent::configLoad($config_file, $sections);
|
||||||
|
|
||||||
$this->compiled->file_dependency[ $confObj->source->uid ] =
|
$this->compiled->file_dependency[ $confObj->source->uid ] =
|
||||||
array($confObj->source->filepath, $confObj->source->getTimeStamp(), $confObj->source->type);
|
array($confObj->source->filepath, $confObj->source->getTimeStamp(), $confObj->source->type);
|
||||||
|
@@ -14,13 +14,6 @@ use Smarty\Exception;
|
|||||||
*/
|
*/
|
||||||
class Config extends Source {
|
class Config extends Source {
|
||||||
|
|
||||||
/**
|
|
||||||
* array of section names, single section or null
|
|
||||||
*
|
|
||||||
* @var null|string|array
|
|
||||||
*/
|
|
||||||
public $config_sections = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flag that source is a config file
|
* Flag that source is a config file
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user