mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-06 11:32:40 +00:00
Add more tests
Fix an issue in IniReader and add tests to ensure that dumped files can be re-read.
This commit is contained in:
parent
7c4b7a2cbe
commit
e7153b5333
3 changed files with 104 additions and 35 deletions
|
@ -128,6 +128,7 @@ class IniReader implements ConfigReaderInterface {
|
|||
if ($value === '') {
|
||||
$value = false;
|
||||
}
|
||||
unset($values[$key]);
|
||||
if (strpos($key, '.') !== false) {
|
||||
$values = Hash::insert($values, $key, $value);
|
||||
} else {
|
||||
|
@ -153,11 +154,31 @@ class IniReader implements ConfigReaderInterface {
|
|||
if (is_array($value)) {
|
||||
$keyValues = Hash::flatten($value, '.');
|
||||
foreach ($keyValues as $k => $v) {
|
||||
$result[] = "$k = " . trim(var_export($v, true), "'");
|
||||
$result[] = "$k = " . $this->_value($v);
|
||||
}
|
||||
}
|
||||
}
|
||||
$contents = join("\n", $result);
|
||||
return file_put_contents($this->_path . $filename, $contents);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a value into the ini equivalent
|
||||
*
|
||||
* @param mixed $value to export.
|
||||
* @return string String value for ini file.
|
||||
*/
|
||||
protected function _value($val) {
|
||||
if ($val === null) {
|
||||
return 'null';
|
||||
}
|
||||
if ($val === true) {
|
||||
return 'true';
|
||||
}
|
||||
if ($val === false) {
|
||||
return 'false';
|
||||
}
|
||||
return (string)$val;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue