function merge(array $data = null)
 {
     if (is_null($data) || is_null($this->model)) {
         return;
     }
     $data = array_normalizeEmptyValues($data, true);
     if (is_array($this->model)) {
         array_recursiveMergeInto($this->model, $data);
     } else {
         if (is_object($this->model)) {
             extend($this->model, $data);
         } else {
             throw new FatalException(sprintf("Can't merge data into a model of type <kbd>%s</kbd>", gettype($this->model)));
         }
     }
 }
Esempio n. 2
0
/**
 * Converts all values that are empty strings to `null`.
 *
 * @param array $array The source array.
 * @param bool  $recursive
 * @return array The modified array.
 */
function array_normalizeEmptyValues(array $array, $recursive = false)
{
    foreach ($array as $k => &$v) {
        if ($v === '') {
            $v = null;
        } elseif ($recursive && is_array($v)) {
            $v = array_normalizeEmptyValues($v, true);
        }
    }
    return $array;
}