Commit 2caa00b46a57ae6514f284d4f6cd13cc02eb14cd
1 parent
5a24d8d4
Add a "default" option to return if a given item isn't in the config
files. Clean up singleton handling to work in strange cases (like when the file is imported within a function). git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3586 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
7 additions
and
6 deletions
lib/config/config.inc.php
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | |
| 3 | 3 | require_once("Config.php"); |
| 4 | 4 | |
| 5 | -define("KT_CONFIG_DEFAULT", true); | |
| 5 | +require_once(KT_LIB_DIR . '/util/ktutil.inc'); | |
| 6 | 6 | |
| 7 | 7 | class KTConfig { |
| 8 | 8 | var $conf = array(); |
| ... | ... | @@ -67,22 +67,23 @@ class KTConfig { |
| 67 | 67 | return $v; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - function get($var) { | |
| 70 | + function get($var, $oDefault = null) { | |
| 71 | 71 | if (array_key_exists($var, $this->flatns)) { |
| 72 | 72 | return $this->expand($this->flatns[$var]); |
| 73 | 73 | } |
| 74 | 74 | if (array_key_exists($var, $this->flat)) { |
| 75 | 75 | return $this->expand($this->flat[$var]); |
| 76 | 76 | } |
| 77 | - return null; | |
| 77 | + return $oDefault;; | |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | function &getSingleton() { |
| 81 | - global $KTConfig; | |
| 82 | - return $KTConfig; | |
| 81 | + if (!KTUtil::arrayGet($GLOBALS, 'KTConfig')) { | |
| 82 | + $GLOBALS['KTConfig'] =& new KTConfig; | |
| 83 | + } | |
| 84 | + return $GLOBALS['KTConfig']; | |
| 83 | 85 | } |
| 84 | 86 | } |
| 85 | 87 | |
| 86 | -$KTConfig =& new KTConfig; | |
| 87 | 88 | |
| 88 | 89 | ?> | ... | ... |