Source for file ini.php
Documentation is available at ini.php
* @package Joomla.Platform
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* INI format handler for JRegistry.
* @package Joomla.Platform
* Cache of processed data
protected static $cache =
array();
* Converts an object into an INI formatted string
* - Unfortunately, there is no way to have ini values nested further than two
* levels deep. Therefore we will only go through the first two levels of
* @param object $object Data source object.
* @param array $options Options used by the formatter.
* @return string INI formatted string.
// Iterate over the object to set the properties.
// If the value is an object then we need to put it in a local section.
$local[] =
'[' .
$key .
']';
// Add the properties for this section.
// Not in a section so add the property to the global array.
* Parse an INI formatted string and convert it into an object.
* @param string $data INI formatted string to convert.
* @param mixed $options An array of options used by the formatter, or a boolean setting to process sections.
* @return object Data object.
$sections =
(isset
($options['processSections'])) ?
$options['processSections'] :
false;
// Check the memory cache for already processed strings.
$hash =
md5($data .
':' . (int)
$sections);
if (isset
(self::$cache[$hash]))
return self::$cache[$hash];
// If no lines present just return the object.
foreach ($lines as $line)
// Trim any unnecessary whitespace.
// Ignore empty lines and comments.
if (empty($line) ||
($line{0} ==
';'))
// If we are processing sections and the line is a section add the object and continue.
if (($line[0] ==
'[') &&
($line[$length -
1] ==
']'))
$section =
substr($line, 1, $length -
2);
$obj->$section =
new stdClass;
// Check that an equal sign exists and is not the first character of the line.
// Maybe throw exception?
// Get the key and value for the line.
list
($key, $value) =
explode('=', $line, 2);
// Maybe throw exception?
// If the value is quoted then we assume it is a string.
if ($length &&
($value[0] ==
'"') &&
($value[$length -
1] ==
'"'))
// Strip the quotes and Convert the new line characters.
// If the value is not quoted, we assume it is not a string.
// If the value is 'false' assume boolean false.
// If the value is 'true' assume boolean true.
elseif ($value ==
'true')
// If the value is numeric than it is either a float or int.
// If there is a period then we assume a float.
if (strpos($value, '.') !==
false)
// If a section is set add the key/value to the section, otherwise top level.
$obj->$section->$key =
$value;
// Cache the string to save cpu cycles -- thus the world :)
self::$cache[$hash] =
clone ($obj);
* Method to get a value in an INI format.
* @param mixed $value The value to convert to INI format.
* @return string The value in INI format.
$string =
$value ?
'true' :
'false';
// Sanitize any CRLF characters..
$string =
'"' .
str_replace(array("\r\n", "\n"), '\\n', $value) .
'"';
Documentation generated on Tue, 19 Nov 2013 15:05:33 +0100 by phpDocumentor 1.4.3