for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Noodlehaus\FileParser;
use Noodlehaus\Exception\ParseException;
/**
* INI file parser
*
* @package Config
* @author Jesus A. Domingo <[email protected]>
* @author Hassan Khan <[email protected]>
* @link https://github.com/noodlehaus/config
* @license MIT
*/
class Ini implements FileParserInterface
{
* {@inheritDoc}
* Parses an INI file as an array
* @throws ParseException If there is an error parsing the INI file
public function parse($path)
$data = @parse_ini_file($path, true);
if (!$data) {
$error = error_get_last();
throw new ParseException($error);
}
return $this->expandDottedKey($data);
* Expand array with dotted keys to multidimensional array
* @param array $data
* @return array
protected function expandDottedKey($data)
foreach ($data as $key => $value) {
if (($found = strpos($key, '.')) !== false) {
$newKey = substr($key, 0, $found);
$remainder = substr($key, $found + 1);
$expandedValue = $this->expandDottedKey([$remainder => $value]);
if (isset($data[$newKey])) {
$data[$newKey] = array_merge_recursive($data[$newKey], $expandedValue);
} else {
$data[$newKey] = $expandedValue;
unset($data[$key]);
return $data;
public static function getSupportedExtensions()
return array('ini');