19 require_once(BASE.
"wcmf/lib/util/class.StringUtil.php");
20 require_once(BASE.
"wcmf/lib/util/class.ArrayUtil.php");
21 require_once(BASE.
"wcmf/lib/core/class.WCMFException.php");
53 static $instance = null;
55 if (!isset($instance))
89 if ($this->_parsedFiles[
sizeof($this->_parsedFiles)-1] == $filename) {
94 if (file_exists($filename))
96 $this->_filename = $filename;
100 $tmpSequence[] = $filename;
107 if (($includes = $this->
getValue(
'include',
'config')) !==
false)
110 foreach($includes as $include)
117 $this->_parsedFiles[] = $filename;
126 $this->_errorMsg =
"Configuration file ".$filename.
" not found!";
146 return array_keys($this->_iniArray);
158 if (
sizeof($matchingKeys) > 0) {
159 $section = array_pop($matchingKeys);
161 if (!isset($this->_iniArray[$section]))
163 $this->_errorMsg =
"Section '".$section.
"' not found!";
167 return $this->_iniArray[$section];
181 if ($sectionArray ===
false) {
185 if (
sizeof($matchingKeys) > 0) {
186 $key = array_pop($matchingKeys);
188 if (!array_key_exists($key, $sectionArray))
190 $this->_errorMsg =
"Key '".$key.
"' not found in section '".$section.
"'!";
194 return $sectionArray[$key];
208 $this->_iniArray = $data;
209 $this->_isModified =
true;
219 if (($hiddenSections = $this->
getValue(
'hiddenSections',
'config')) !==
false)
222 if (is_array($hiddenSections) && in_array($section, $hiddenSections))
235 if (($readonlySections = $this->
getValue(
'readonlySections',
'config')) !==
false)
238 if (is_array($readonlySections) && in_array($section, $readonlySections))
251 $section = trim($section);
254 $this->_errorMsg =
"Section '".$section.
"' already exists!";
259 $this->_errorMsg =
"Empty section names are not allowed!";
262 $this->_iniArray[$section] =
'';
263 $this->_isModified =
true;
276 $this->_errorMsg =
"Section ".$section.
" is not editable!";
281 unset($this->_iniArray[$section]);
282 $this->_isModified =
true;
296 $this->_errorMsg =
"Section ".$oldname.
" is not editable!";
299 $newname = trim($newname);
304 $this->_errorMsg =
"Section '".$newname.
"' already exists!";
309 $this->_errorMsg =
"Empty section names are not allowed!";
313 $this->_isModified =
true;
325 function setValue($key, $value, $section, $createSection=
true)
329 $this->_errorMsg =
"Section ".$section.
" is not editable!";
333 if (!$createSection && ($this->
getSection($section) ===
false))
337 $this->_errorMsg =
"Empty key names are not allowed!";
340 $this->_iniArray[$section][$key] = $value;
341 $this->_isModified =
true;
355 $this->_errorMsg =
"Section ".$section.
" is not editable!";
358 if ($this->
getValue($key, $section) ===
false)
360 unset($this->_iniArray[$section][$key]);
361 $this->_isModified =
true;
376 $this->_errorMsg =
"Section ".$section.
" is not editable!";
379 $newname = trim($newname);
380 if ($this->
getValue($oldname, $section) ===
false)
382 if ($this->
getValue($newname, $section) !==
false)
384 $this->_errorMsg =
"Key '".$newname.
"' already exists in section '".$section.
"'!";
389 $this->_errorMsg =
"Empty key names are not allowed!";
393 $this->_isModified =
true;
404 if ($filename == null)
408 foreach($this->_iniArray as $section => $values)
410 $sectionString =
"[".$section.
"]";
411 $content .= $this->_comments[$sectionString];
412 $content .= $sectionString.
"\n";
413 if (is_array($values))
415 foreach($values as $key => $value)
417 if (is_array($value))
418 $value =
"{".join(
", ", $value).
"}";
420 $value = str_replace(
"\\\"",
"\"", $value);
421 $content .= $this->_comments[$section][$key];
422 $content .= $key.
" = ".$value.
"\n";
426 $content .= $this->_comments[
';'];
428 if (!$fh = fopen($filename,
'w'))
430 $this->_errorMsg =
"Can't open ini file '".$filename.
"'!";
434 if (!fwrite($fh, $content))
436 $this->_errorMsg =
"Can't write ini file '".$filename.
"'!";
440 $this->_isModified =
false;
461 if (!file_exists($filename))
464 $ini_array = array();
466 $lines = file($filename);
467 $commentsPending =
"";
468 foreach($lines as $line)
472 if($line ==
"" || $line[0] ==
";")
474 $commentsPending .= $line.
"\n";
478 if($line[0] ==
"[" && $line[strlen($line)-1] ==
"]")
480 $sec_name = substr($line, 1, strlen($line)-2);
481 $ini_array[$sec_name] = array();
484 $this->_comments[$line] = $commentsPending;
485 $commentsPending =
"";
489 $parts = explode(
"=", $line, 2);
490 $property = trim($parts[0]);
491 $value = trim($parts[1]);
492 $ini_array[$sec_name][$property] = $value;
495 $this->_comments[$sec_name][$property] = $commentsPending;
496 $commentsPending =
"";
500 $this->_comments[
';'] = substr($commentsPending, 0, -1);
513 array_walk_recursive($this->_iniArray, array($this,
'processValue'));
525 if (!is_array($value))
528 if (preg_match (
"/%/", $value))
529 $value = urldecode($value);
531 if(preg_match(
"/^{.*}$/", $value))
535 foreach ($arrayValues as $arrayValue)
536 array_push($value, trim($arrayValue));
552 foreach(array_keys($array2) as $key)
554 if (!array_key_exists($key, $result))
555 $result[$key] = $array2[$key];
557 foreach(array_keys($array2[$key]) as $subkey)
559 if ((array_key_exists($subkey, $result[$key]) && $override) || !isset($result[$key][$subkey]))
560 $result[$key][$subkey] = $array2[$key][$subkey];
574 if($fh = @fopen($cacheFile,
"w"))
576 if(@fwrite($fh,
serialize(get_object_vars($this))))
596 if (file_exists($cacheFile))
600 $vars =
unserialize(file_get_contents($cacheFile));
603 if (isset($vars[
'_iniArray'][
'config']))
606 $includes = $vars[
'_iniArray'][
'config'][
'include'];
607 if (is_array($includes))
609 $includedFiles = array();
610 foreach($includes as $include) {
611 $includedFiles[] = $CONFIG_PATH.$include;
620 foreach($vars as $key=>$val)
622 eval(
"$".
"this->$key = $".
"vars['".
"$key'];");
638 $path = session_save_path();
639 $filename = $path.
'/'.urlencode(realpath($CONFIG_PATH).
"/".join(
'_', $parsedFiles));
651 foreach ($fileList as $file) {
652 if (filemtime($file) > filemtime($referenceFile)) {
parseIniFile($filename, $processValues=true)
get_matching_values_i($str, $array)
_parse_ini_file($filename)
throwEx($message, $file='', $line='')
key_array_rename(&$input, $oldname, $newname)
removeKey($key, $section)
checkFileDate($fileList, $referenceFile)
InifileParser provides basic services for parsing a ini file from the file system.
renameKey($oldname, $newname, $section)
renameSection($oldname, $newname)
writeIniFile($filename=null)
configMerge($array1, $array2, $override)
unserialize($parsedFiles)
setValue($key, $value, $section, $createSection=true)
getSerializeFilename($parsedFiles)