Adding initial version of OVERRIDE(..) macro
This commit is contained in:
parent
d079c79d50
commit
24b2a0ee45
|
@ -171,3 +171,39 @@ function macro_UNWRAP($jsm, $content)
|
|||
$content = rtrim($content, '}');
|
||||
return $content;
|
||||
}
|
||||
|
||||
function _array_merge_recursive_distinct(array $array1, array $array2)
|
||||
{
|
||||
$merged = $array1;
|
||||
|
||||
foreach($array2 as $key => $value)
|
||||
{
|
||||
if(is_array($value) && isset($merged[$key]) && is_array($merged[$key]))
|
||||
$merged[$key] = _array_merge_recursive_distinct($merged[$key], $value);
|
||||
else
|
||||
$merged[$key] = $value;
|
||||
}
|
||||
|
||||
return $merged;
|
||||
}
|
||||
|
||||
/**
|
||||
* @global @raw_args
|
||||
*/
|
||||
function macro_OVERRIDE($jsm, $content)
|
||||
{
|
||||
$items = \jzon_parse($content);
|
||||
if(!is_array($items))
|
||||
throw new Exception("OVERRIDE contents not an array");
|
||||
if(sizeof($items) != 2)
|
||||
throw new Exception("OVERRIDE array size is not 2, it's " . sizeof($items));
|
||||
|
||||
$merged = _array_merge_recursive_distinct($items[0], $items[1]);
|
||||
|
||||
$json = json_encode($merged, JSON_UNESCAPED_LINE_TERMINATORS | JSON_UNESCAPED_SLASHES);
|
||||
$json = ltrim($json, '{');
|
||||
$json = rtrim($json, '}');
|
||||
|
||||
return $json;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue