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:
parent
9611f0b78f
commit
fc7579b5e6
1 changed files with 13 additions and 3 deletions
|
@ -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) )
|
||||
|
|
Loading…
Reference in a new issue