mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-03 18:04: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"),
|
||||
str_replace('*/', '* /', $this->template->source->filepath)
|
||||
);
|
||||
$code = '<?php $_smarty_tpl->assignConfigVars(' .
|
||||
var_export($this->config_data, true) . '); ?>';
|
||||
$code = '<?php $_smarty_tpl->parent->assignConfigVars(' .
|
||||
var_export($this->config_data, true) . ', $_smarty_tpl->getValue("sections")); ?>';
|
||||
return $template_header . $this->template->createCodeFrame($code);
|
||||
}
|
||||
|
||||
|
63
src/Data.php
63
src/Data.php
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Smarty;
|
||||
|
||||
use Smarty\Template\Config;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Data
|
||||
* 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
|
||||
*/
|
||||
public function assignConfigVars($new_config_vars) {
|
||||
public function assignConfigVars($new_config_vars, array $sections = []) {
|
||||
|
||||
// copy global config vars
|
||||
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;
|
||||
} else {
|
||||
$this->config_vars[$variable] = array_merge((array)$this->config_vars[$variable], (array)$value);
|
||||
}
|
||||
}
|
||||
// scan sections
|
||||
$sections = $this->source->config_sections;
|
||||
if (!empty($sections)) {
|
||||
foreach ((array)$sections as $tpl_section) {
|
||||
if (isset($new_config_vars['sections'][$tpl_section])) {
|
||||
foreach ($new_config_vars['sections'][$tpl_section]['vars'] as $variable => $value) {
|
||||
if ($this->smarty->config_overwrite || !isset($this->config_vars[$variable])) {
|
||||
$this->config_vars[$variable] = $value;
|
||||
} else {
|
||||
$this->config_vars[$variable] = array_merge((array)$this->config_vars[$variable], (array)$value);
|
||||
}
|
||||
|
||||
foreach ($sections as $tpl_section) {
|
||||
if (isset($new_config_vars['sections'][$tpl_section])) {
|
||||
foreach ($new_config_vars['sections'][$tpl_section]['vars'] as $variable => $value) {
|
||||
if ($this->_getSmartyObj()->config_overwrite || !isset($this->config_vars[$variable])) {
|
||||
$this->config_vars[$variable] = $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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
@@ -410,23 +390,22 @@ abstract class Data
|
||||
* @param mixed $sections array of section names, single
|
||||
* section or null
|
||||
|
||||
* @returns Template
|
||||
* @returns $this
|
||||
* @throws \Exception
|
||||
* @link https://www.smarty.net/docs/en/api.config.load.tpl
|
||||
*
|
||||
* @api Smarty::configLoad()
|
||||
*/
|
||||
protected function _loadConfigfile($config_file, $sections = null)
|
||||
public function configLoad($config_file, $sections = null)
|
||||
{
|
||||
$smarty = $this->_getSmartyObj();
|
||||
|
||||
$confObj = new Template($config_file, $smarty, $this, null, null, null, null, true);
|
||||
$confObj->caching = Smarty::CACHING_OFF;
|
||||
$confObj->source->config_sections = $sections;
|
||||
$confObj->compiled = \Smarty\Template\Compiled::load($confObj);
|
||||
$confObj->compiled->render($confObj);
|
||||
return $confObj;
|
||||
$template = new Template($config_file, $smarty, $this, null, null, null, null, true);
|
||||
$template->caching = Smarty::CACHING_OFF;
|
||||
$template->assign('sections', (array) $sections ?? []);
|
||||
// trigger a call to $this->assignConfigVars
|
||||
$template->compiled = \Smarty\Template\Compiled::load($template);
|
||||
$template->compiled->render($template);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -693,9 +693,9 @@ class Template extends TemplateBase {
|
||||
/**
|
||||
* @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 ] =
|
||||
array($confObj->source->filepath, $confObj->source->getTimeStamp(), $confObj->source->type);
|
||||
|
@@ -14,13 +14,6 @@ use Smarty\Exception;
|
||||
*/
|
||||
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
|
||||
*
|
||||
|
Reference in New Issue
Block a user