partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 51f392f570ded10d3b7c59c15e326ca4c2416437
parent 8c1385a7a033ef2fded7e5bc281821dd41278b57
Author: Felicitus <felicitus@felicitus.org>
Date:   Fri, 10 Feb 2012 01:55:03 +0100

Throw a SerializableException instead of outputting an error message + direct exit

Diffstat:
Msrc/backend/de/RaumZeitLabor/PartKeepr/Setup/ConfigFileSetup.php | 16+++++++++++-----
Msrc/backend/de/RaumZeitLabor/PartKeepr/Util/SerializableException.php | 3++-
2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/Setup/ConfigFileSetup.php b/src/backend/de/RaumZeitLabor/PartKeepr/Setup/ConfigFileSetup.php @@ -2,7 +2,8 @@ namespace de\RaumZeitLabor\PartKeepr\Setup; use de\RaumZeitLabor\PartKeepr\Util\Configuration, - de\RaumZeitLabor\PartKeepr\PartKeepr; + de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Util\SerializableException; /** * Creates a new config file @@ -12,13 +13,18 @@ class ConfigFileSetup extends AbstractSetup { $configFile = PartKeepr::getRootDirectory()."/config.php"; if (file_exists($configFile)) { if (!is_writable($configFile)) { - echo json_encode(array("error" => true, "errormessage" => "The config.php file could not be written, because it already exists and the webserver has no write access to it.")); - exit; + $message = "The config.php file could not be written, because it already exists and the webserver has "; + $message .= "no write access to it."; + + throw new SerializableException($message, 10000); + /*echo json_encode(array("error" => true, "errormessage" => )); + exit;*/ } } else { if (!is_writable(PartKeepr::getRootDirectory())) { - echo json_encode(array("error" => true, "errormessage" => "The config.php file could not be written, because the webserver has no write access to it.")); - exit; + $message = "The config.php file could not be written, because the webserver has no write access to it."; + + throw new SerializableException($message, 10001); } } file_put_contents($configFile, Configuration::dumpConfig()); diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/Util/SerializableException.php b/src/backend/de/RaumZeitLabor/PartKeepr/Util/SerializableException.php @@ -17,7 +17,8 @@ class SerializableException extends \Exception { return array( "message" => $this->getMessage(), "detail" => $this->getDetail(), - "exception" => get_class($this) + "exception" => get_class($this), + "code" => $this->getCode() //"backtrace" => $this->getFormattedTrace() ); }