5 * @subpackage PluginsInternal
7 class Smarty_Internal_Extension_Config
12 * @param null $sections
13 * @param string $scope
15 static function configLoad($obj, $config_file, $sections = null, $scope = 'local')
17 $smarty = isset($obj->smarty
) ?
$obj->smarty
: $obj;
18 $confObj = new $smarty->template_class($config_file, $smarty, $obj);
19 $confObj->caching
= Smarty
::CACHING_OFF
;
20 $confObj->source
= Smarty_Template_Config
::load($confObj);
21 $confObj->source
->config_sections
= $sections;
22 $confObj->source
->scope
= $scope;
23 $confObj->compiled
= Smarty_Template_Compiled
::load($confObj);
24 if ($confObj->smarty
->debugging
) {
25 Smarty_Internal_Debug
::start_render($confObj);
27 $confObj->compiled
->render($confObj);
28 if ($confObj->smarty
->debugging
) {
29 Smarty_Internal_Debug
::end_render($confObj);
31 if ($obj instanceof Smarty_Internal_Template
) {
32 $obj->properties
['file_dependency'][$confObj->source
->uid
] = array($confObj->source
->filepath
, $confObj->source
->timestamp
, $confObj->source
->type
);
37 * load config variables
39 * @param mixed $sections array of section names, single section or null
40 * @param string $scope global,parent or local
44 static function loadConfigVars($_template, $_config_vars)
46 $scope = $_template->source
->scope
;
47 // pointer to scope (local scope is parent of template object
48 $scope_ptr = $_template->parent
;
49 if ($scope == 'parent') {
50 if (isset($_template->parent
->parent
)) {
51 $scope_ptr = $_template->parent
->parent
;
53 } elseif ($scope == 'root' ||
$scope == 'global') {
54 while (isset($scope_ptr->parent
)) {
55 $scope_ptr = $scope_ptr->parent
;
58 // copy global config vars
59 foreach ($_config_vars['vars'] as $variable => $value) {
60 if ($_template->smarty
->config_overwrite ||
!isset($scope_ptr->config_vars
[$variable])) {
61 $scope_ptr->config_vars
[$variable] = $value;
63 $scope_ptr->config_vars
[$variable] = array_merge((array) $scope_ptr->config_vars
[$variable], (array) $value);
67 $sections = $_template->source
->config_sections
;
68 if (!empty($sections)) {
69 foreach ((array) $sections as $_template_section) {
70 if (isset($_config_vars['sections'][$_template_section])) {
71 foreach ($_config_vars['sections'][$_template_section]['vars'] as $variable => $value) {
72 if ($_template->smarty
->config_overwrite ||
!isset($scope_ptr->config_vars
[$variable])) {
73 $scope_ptr->config_vars
[$variable] = $value;
75 $scope_ptr->config_vars
[$variable] = array_merge((array) $scope_ptr->config_vars
[$variable], (array) $value);
84 * Returns a single or all config variables
86 * @param string $varname variable name or null
87 * @param bool $search_parents
89 * @return string variable value or or array of variables
91 static function getConfigVars($obj, $varname = null, $search_parents = true)
95 while ($_ptr !== null) {
96 if (isset($varname)) {
97 if (isset($_ptr->config_vars
[$varname])) {
98 return $_ptr->config_vars
[$varname];
101 $var_array = array_merge($_ptr->config_vars
, $var_array);
103 // not found, try at parent
104 if ($search_parents) {
105 $_ptr = $_ptr->parent
;
110 if (isset($varname)) {
118 * gets a config variable
120 * @param string $variable the name of the config variable
121 * @param bool $error_enable
123 * @return mixed the value of the config variable
125 static function getConfigVariable($obj, $variable, $error_enable = true)
128 while ($_ptr !== null) {
129 if (isset($_ptr->config_vars
[$variable])) {
130 // found it, return it
131 return $_ptr->config_vars
[$variable];
133 // not found, try at parent
134 $_ptr = $_ptr->parent
;
136 if ($smarty->error_unassigned
&& $error_enable) {
145 * remove a single or all config variables
147 * @param string $name variable name or null
149 * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
151 static function clearConfig($obj, $name = null)
154 unset($obj->config_vars
[$name]);
156 $obj->config_vars
= array();