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;
        }

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.

The following function will do that. It will use a value set in the
following order:
first priority if it is already set in a config file,
second priority if it is set in site.config,
third priority if it is set as a default.
And one can pass a value or an array.

The new function:

function BOLTdefault(&$var, $key, $def) {
## SYSTEM FUNCTION FOR SETTING DEFAULT VALUES WHICH CAN BE PRESET IN A
CONFIG FILE OR site.config
        global $BOLTconfig;
        if (is_array($def)) {
                foreach($def as $f=>$d)
                        if (!isset($var[$f]))
                                $var[$f] = (isset($BOLTconfig[$key][$f])) ? 
$BOLTconfig[$key][$f] : $d;
        } else if (!isset($var))
        $var = (isset($BOLTconfig[$key])) ? $BOLTconfig[$key] : $def;
}

then in a script (plugin or whatever) I can use for instance

BOLTdefault($toggleConfig,'toggle', array(
        'init' => 'show',
        'show' => "Show",
        'hide' => "Hide",
));

so BOLTdefault sets the var $toggleConfig, in this example as an
array, and sets the values according to priority.

One little niggle, which may be actually a good thing, is that I
needed to introduce a $key, which is the string used in site.config
for setting a value. By passing a variable to a function I don't know
how to use the name of the variable in the function. The name is
required to check the $BOLTconfig field (key) of that name.

So in site.config we can set values for the array like

toggle:show: Make form visible!
toggle:hide: Hide this form

or in a config file we could use for instance

$toggleConfig['show'] = 'Versteck mich';
$toggleConfig['hide'] = 'Zeig mich';

And I guess calling BOLTconfig function would not be needed when using
this new BOLTdefault() function to set defaults.

Cheers,
~Hans

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to