Simplified framing default option handling.

This commit is contained in:
Dave Longley 2011-07-29 15:34:43 -04:00
parent 6810f94673
commit 25c62ddac1

View file

@ -2636,12 +2636,12 @@ function _frame($subjects, $input, $frame, $embeds, $options)
} }
else else
{ {
// add null property to value // add empty array/null property to value
$value->$key = null; $value->$key = is_array($f) ? array() : null;
} }
// handle setting default value(s) // handle setting default value
if(property_exists($value, $key)) if($value->$key === null)
{ {
// use first subframe if frame is an array // use first subframe if frame is an array
if(is_array($f)) if(is_array($f))
@ -2653,37 +2653,13 @@ function _frame($subjects, $input, $frame, $embeds, $options)
$omitOn = property_exists($f, '@omitDefault') ? $omitOn = property_exists($f, '@omitDefault') ?
$f->{'@omitDefault'} : $f->{'@omitDefault'} :
$options->defaults->omitDefaultOn; $options->defaults->omitDefaultOn;
if($omitOn)
if($value->$key === null)
{ {
if($omitOn) unset($value->$key);
{
unset($value->$key);
}
else if(property_exists($f, '@default'))
{
$value->$key = $f->{'@default'};
}
} }
else if(is_array($value->$key)) else if(property_exists($f, '@default'))
{ {
$tmp = array(); $value->$key = $f->{'@default'};
foreach($value->$key as $v)
{
if($v === null)
{
// do not auto-include null in arrays
if(!$omitOn and property_exists($f, '$default'))
{
$tmp[] = $f->{'$default'};
}
}
else
{
$tmp[] = $v;
}
}
$value->$key = $tmp;
} }
} }
} }