On Mon, Feb 23, 2009 at 7:25 AM, Hans <[email protected]> wrote:
>
> The new function BOLTdefaultArray does not work. It should read
>
> function BOLTdefaultArray(&$array,$default) {
> ## SYSTEM FUNCTION USED TO DEFINE DEFAULT ARRAYS THAT CAN BE
> OVERRIDDEN IN CONFIG FILE
> foreach($default as $f=>$v) if (!isset($array[$f])) $array[$f]=$v;
> }
Oops. Sorry about that. Thank you! Fixed for next release.
> BUT I think we can do much better than this. We do want to check not
> only if a value has been set already, and use that instead of the
> default array value, but we also want to check if the value is set on
> site.config, i.e. if it is already in the $BOLTconfig array.
> So we can expand the function to do that too. But we can and should do
> the same for the BOLTdefault function.
> In fact we can combine both functions into one, which checks both
> values and arrays passed.
Actually, I think this is the backward approach. BOLTdefault is only
used in two situations in the core: 1) when settings need to be
assigned before site.config is loaded (usually index.php type
settings). And 2) with complex values that should not be put in
site.config. In other words BOLTconfig is the main way of loading
vars, not BOLTdefault, which is only for anything that DOESN'T check
site.config.
As for BOLTdefaultArray, I notice you can already load arrays with
BOLTdefault (Notice line ~1899 in engine.php). It works slightly
different from BOLTdefaultArray, which can override specific values
rather than the whole array, but I question whether or not
BOLTdefaultArray is really needed... We've managed to do ok so far...
The only problem is BOLTconfig doesn't yet know how to handle
arrays... So I added this code, as a first draft:
function BOLTconfig($field, $default='') {
## SYSTEM FUNCTION USED TO RETRIEVE CONFIG VALUES FOUND IN SITE CONFIG
global $BOLTconfig;
if (substr($field, 0, 4) == 'BOLT') {
$field = strtolower(substr($field, 4));
if (strpos($field, ':')) {
$a = substr($field, 0, strpos($field, ':'));
$k = substr($field, strpos($field, ':') + 1);
if (isset($BOLTconfig[$a][$k])) return
$BOLTconfig[$a][$k];
return $default;
}
if (isset($BOLTconfig[$field])) return $BOLTconfig[$field];
return $default;
}
}
Then you can set array values like this:
$test['three'] = BOLTconfig('BOLTtest:three', 'hi'));
There may be a better way to do this, but, I think the main point is
BOLTconfig is for stuff that goes through site.config. BOLTdefault is
for special cases that cannot or do not use site.config for some
reason.
Cheers,
Dan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"BoltWire" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/boltwire?hl=en
-~----------~----~----~----~------~----~------~--~---