config : return a Exception code when there is an error

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2183 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2015-05-16 14:51:53 +00:00
parent 9493e5a1db
commit 016fac4be3

View File

@@ -54,7 +54,7 @@ class config
$conf = array (); $conf = array ();
$rc = include ($this->confFile); $rc = include ($this->confFile);
if ($rc !== 1) if ($rc !== 1)
throw new Exception ("Error in configuration file"); throw new Exception ("Error in configuration file", 500);
return $conf; return $conf;
} }
@@ -65,7 +65,7 @@ class config
{ {
$this->selectConfFile (); $this->selectConfFile ();
if (!array_key_exists ($param, $this->default)) if (!array_key_exists ($param, $this->default))
throw new Exception ("Unknown parameter '$param'"); throw new Exception ("Unknown parameter '$param'", 500);
if (!file_exists ($this->confFile)) if (!file_exists ($this->confFile))
{ {
if (@file_put_contents ($this->confFile, if (@file_put_contents ($this->confFile,
@@ -73,7 +73,7 @@ class config
=== FALSE) === FALSE)
throw new Exception (sprintf (dgettext("domframework", throw new Exception (sprintf (dgettext("domframework",
"No configuration file '%s' available and it can't be created"), "No configuration file '%s' available and it can't be created"),
$this->confFile)); $this->confFile), 500);
} }
elseif (! is_readable ($this->confFile)) elseif (! is_readable ($this->confFile))
throw new Exception (sprintf ( dgettext("domframework", throw new Exception (sprintf ( dgettext("domframework",
@@ -82,7 +82,7 @@ class config
$conf = array (); $conf = array ();
$rc = include ($this->confFile); $rc = include ($this->confFile);
if ($rc !== 1) if ($rc !== 1)
throw new Exception ("Error in configuration file"); throw new Exception ("Error in configuration file", 500);
if (array_key_exists ($param, $conf)) if (array_key_exists ($param, $conf))
{ {
if (! is_array ($conf[$param])) if (! is_array ($conf[$param]))
@@ -110,7 +110,7 @@ class config
{ {
$this->selectConfFile (); $this->selectConfFile ();
if (!array_key_exists ($param, $this->default)) if (!array_key_exists ($param, $this->default))
throw new Exception ("Unknown parameter '$param'"); throw new Exception ("Unknown parameter '$param'", 500);
if (!file_exists ($this->confFile)) if (!file_exists ($this->confFile))
{ {
if (@file_put_contents ($this->confFile, if (@file_put_contents ($this->confFile,
@@ -124,11 +124,11 @@ class config
throw new Exception (sprintf ( throw new Exception (sprintf (
dgettext("domframework", dgettext("domframework",
"The configuration file '%s' is not readable"), "The configuration file '%s' is not readable"),
$this->confFile)); $this->confFile), 500);
if (!is_writeable ($this->confFile)) if (!is_writeable ($this->confFile))
throw new Exception (sprintf (dgettext("domframework", throw new Exception (sprintf (dgettext("domframework",
"Configuration file '%s' is write protected"), "Configuration file '%s' is write protected"),
$this->confFile)); $this->confFile), 500);
$conf = array (); $conf = array ();
$rc = include ($this->confFile); $rc = include ($this->confFile);
if ($rc !== 1) if ($rc !== 1)
@@ -143,7 +143,7 @@ class config
if (@file_put_contents ($this->confFile, $txt, LOCK_EX) === FALSE) if (@file_put_contents ($this->confFile, $txt, LOCK_EX) === FALSE)
throw new Exception (sprintf (dgettext("domframework", throw new Exception (sprintf (dgettext("domframework",
"Can't save configuration file '%s'"), "Can't save configuration file '%s'"),
$this->confFile)); $this->confFile), 500);
return TRUE; return TRUE;
} }