From b4411569347e4a945a768ae3f0c1f7c6cefe9eed Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Tue, 22 Sep 2015 11:54:13 +0200 Subject: [PATCH] Implement IniParser::parseIniFile() refs #10150 --- library/Icinga/File/Ini/IniParser.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/library/Icinga/File/Ini/IniParser.php b/library/Icinga/File/Ini/IniParser.php index 43c96836d..b22841f78 100644 --- a/library/Icinga/File/Ini/IniParser.php +++ b/library/Icinga/File/Ini/IniParser.php @@ -9,6 +9,7 @@ use Icinga\File\Ini\Dom\Document; use Icinga\File\Ini\Dom\Directive; use Icinga\Application\Logger; use Icinga\Exception\ConfigurationError; +use Icinga\Exception\NotReadableError; class IniParser { @@ -239,4 +240,25 @@ class IniParser } 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); + } }