Allow Utils::setDotNotation to merge data, rather than just set.

This commit is contained in:
Djamil Legato
2016-08-27 12:29:11 -07:00
parent b73f92c78c
commit 1bfe99b9cd
2 changed files with 15 additions and 5 deletions

View File

@@ -15,6 +15,7 @@
* Added support for `self@`, `page@`, `taxonomy@`, `root@` Collection syntax for cleaner YAML compatibility
* Improved GPM commands to allow for `-y` to automate **yes** responses and `-o` for **update** and **selfupgrade** to overwrite installations [#985](https://github.com/getgrav/grav/issues/985)
* Added randomization to `safe_email` Twig filter for greater security [#998](https://github.com/getgrav/grav/issues/998)
* Allow `Utils::setDotNotation` to merge data, rather than just set
1. [](#bugfix)
* Removed 307 redirect code option as it is not well supported [#743](https://github.com/getgrav/grav-plugin-admin/issues/743)
* Fixed issue with folders with name `*.md` are not confused with pages [#995](https://github.com/getgrav/grav/issues/995)

View File

@@ -711,12 +711,14 @@ abstract class Utils
* Set portion of array (passed by reference) for a dot-notation key
* and set the value
*
* @param $array
* @param $key
* @param $value
* @param $array
* @param $key
* @param $value
* @param bool $merge
*
* @return mixed
*/
public static function setDotNotation(&$array, $key, $value)
public static function setDotNotation(&$array, $key, $value, $merge = false)
{
if (is_null($key)) return $array = $value;
@@ -734,7 +736,14 @@ abstract class Utils
$array =& $array[$key];
}
$array[array_shift($keys)] = $value;
$key = array_shift($keys);
if (!$merge || !isset($array[$key])) {
$array[$key] = $value;
} else {
$array[$key] = array_merge($array[$key], $value);
}
return $array;
}