From 4ec62ff606e9e50e9216815262a97f68ddd7d285 Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Wed, 4 Jan 2012 19:20:23 +0000 Subject: [PATCH] Add default value for config setting get() --- source/lib/SihnonFramework/Config.class.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/source/lib/SihnonFramework/Config.class.php b/source/lib/SihnonFramework/Config.class.php index 1f804ab..5dde872 100644 --- a/source/lib/SihnonFramework/Config.class.php +++ b/source/lib/SihnonFramework/Config.class.php @@ -109,9 +109,13 @@ class SihnonFramework_Config { * * @param string $key Name of the setting */ - public function get($key) { - if (!isset($this->settings[$key])) { - throw new Sihnon_Exception_UnknownSetting($key); + public function get($key, $default = 'SihnonFramework_Exception_UnknownSetting') { + if ( ! isset($this->settings[$key])) { + if (is_string($default) && preg_match('/^Sihnon(Framework)?_Exception/', $default) && class_exists($default) && is_subclass_of($default, 'SihnonFramework_Exception')) { + throw new $default(); + } + + return $default; } return static::unpack($this->settings[$key]['type'], $this->settings[$key]['value']);