Skip to content

Commit

Permalink
Implement IniParser::parseIniFile()
Browse files Browse the repository at this point in the history
refs #10150
  • Loading branch information
Al2Klimov committed Sep 22, 2015
1 parent 30fa554 commit b441156
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions library/Icinga/File/Ini/IniParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Icinga\File\Ini\Dom\Directive;
use Icinga\Application\Logger;
use Icinga\Exception\ConfigurationError;
use Icinga\Exception\NotReadableError;

class IniParser
{
Expand Down Expand Up @@ -239,4 +240,25 @@ public static function parseIni($str)
}
return $doc;
}

/**
* Read the ini file and parse it with ::parseIni()
*
* @param string $file The ini file to read
*
* @return Document A mutable DOM object
* @throws NotReadableError When the file cannot be read
*/
public static function parseIniFile($file)
{
if (false === ($path = realpath($file))) {
throw new NotReadableError('couldn\'t compute the absolute path of `%s\'', $file);
}

if (false === ($content = file_get_contents($path))) {
throw new NotReadableError('couldn\'t read the file `%s\'', $path);
}

return self::parseIni($content);
}
}

0 comments on commit b441156

Please sign in to comment.