fixes a bug that did not let you write an empty array (infinite loop)

and handles types correctly
boolean values are writte as true/false
null as null
numbers without quotes
This commit is contained in:
Norbert Wagner 2021-05-04 17:53:42 +02:00
parent 9611f0b78f
commit fc7579b5e6

View file

@ -81,18 +81,28 @@ class SettingsWriter
foreach ($settings as $key => $value)
{
fwrite( $this->handle, "$indent'$key' =>" );
if (!is_numeric($key)) $key = "'$key'";
fwrite( $this->handle, "$indent$key =>" );
// recursive walk through child arrays
if ( is_array( $value ) )
{
fwrite( $this->handle, "\n{$indent}[\n" );
$this->write( $value );
if (!empty($value)) $this->write( $value );
fwrite( $this->handle, "$indent]" );
}
else
{
fwrite( $this->handle, " '$value'" );
switch (gettype($value))
{
case 'NULL':
$value = 'null'; break;
case 'boolean':
$value = ($value) ? 'true' : 'false'; break;
case 'string':
$value = "'$value'"; break;
}
fwrite( $this->handle, " $value" );
}
if ( next($settings) )