Closed diosmosis closed 9 years ago
Having the pseudo-file "<string>"
for errors while reading a string doesn't really make sense IMO. Instead I would have a IniFileReadingException extends IniReadingException
with a getFilename()
method.
That way you can do:
try {
...
} catch (IniFileReadingException $e) {
$file = $e->getFilename();
// do something with the file
} catch (IniReadingException $e) {
// do something else?
}
Actually I'm not even sure it belongs here?
If the problem is this part:
public function reload($defaultSettingsFiles = array(), $userSettingsFile = null)
{
// ...
foreach ($this->settingsChain as $file => $ignore) {
if (is_readable($file)) {
$this->settingsChain[$file] = $reader->readFile($file);
}
}
// ...
and the calling code:
try {
$this->settings->reload(array($this->pathGlobal, $this->pathCommon), $this->pathLocal);
} catch (IniReadingException ...
I would simply change the calling code:
public function reload($defaultSettingsFiles = array(), $userSettingsFile = null)
{
// ...
foreach ($this->settingsChain as $file => $ignore) {
if (is_readable($file)) {
try {
$this->settingsChain[$file] = $reader->readFile($file);
} catch (IniReadingException) {
throw new Exception(Piwik::translate('General_ExceptionUnreadableFileDisabledMethod', array($file, "parse_ini_file()")));
}
}
}
// ...
I.e. no need to change the library here, if there's an exception in readFile()
, it's pretty obvious which file is causing the exception.
Also with the current code you will be showing the error:
The INI file is not readable or
parse_ini_file()
is disabled
That's not correct:
parse_ini_file()
is disabled we have a fallback, so it will still workI'm afraid it will only confuse people.
You're right, changing the calling code is better. I didn't change any of the exception messages, so whatever it is, is what was there before. Perhaps it can be improved.
...so file w/ error can be determined when multiple INI files are processed sequentially.
Necessary for https://github.com/piwik/piwik/pull/7312