inifile : return an integer/float if the value is a number

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2562 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2016-02-25 08:37:00 +00:00
parent e0b5b720c9
commit 1ad99a3641
2 changed files with 42 additions and 49 deletions

View File

@@ -18,31 +18,7 @@ class inifile
if (! is_readable ($file))
throw new \Exception (sprintf (dgettext("domframework",
"File '%s' not readable"), $file), 500);
$res = parse_ini_file ($file, $sections);
// The DomFramework is PHP 5.3 compatible. I need to overwrite the bools and
// null values. The INI_SCANNER_TYPED is available as PHP 5.6.1
foreach ($res as $key=>$val)
{
if ($val === "null")
$res[$key] = null;
elseif ($val === "true")
$res[$key] = true;
elseif ($val === "false")
$res[$key] = false;
elseif (is_array ($val))
{
foreach ($val as $k=>$v)
{
if ($v === "null")
$res[$key][$k] = null;
elseif ($v === "true")
$res[$key][$k] = true;
elseif ($v === "false")
$res[$key][$k] = false;
}
}
}
return $res;
return $this->getString (file_get_contents ($file, $sections));
}
/** Return an array with the .ini string content
@@ -71,8 +47,12 @@ class inifile
$res[$key][$k] = true;
elseif ($v === "false")
$res[$key][$k] = false;
elseif (is_numeric ($v))
$res[$key][$k] = $v + 0;
}
}
elseif (is_numeric ($val))
$res[$key] = $val + 0;
}
return $res;
}