function set_subelement($compound, $subspath, $value)
{
    if (empty($subspath) && !($subspath === 0)) {
        return $value;
    }
    if (is_array($subspath)) {
        $level = array_shift($subspath);
    } else {
        $level = $subspath;
        $subspath = NULL;
    }
    if (is_array($compound)) {
        if (!array_key_exists($level, $compound)) {
            $compound[$level] = array();
        }
        $result = set_subelement($compound[$level], $subspath, $value);
        if (is_null($result)) {
            return NULL;
        } else {
            $compound[$level] = $result;
        }
    } elseif (is_object($compound)) {
        if (!property_exists($level, $compound)) {
            $compound->{$level} = array();
        }
        $result = set_subelement($compound->{$level}, $subspath, $value);
        if (is_null($result)) {
            return NULL;
        } else {
            $compound->{$level} = $result;
        }
    } else {
        return NULL;
    }
    return $compound;
}
Exemple #2
0
 protected function new_element(&$signal)
 {
     $value = $this->new_element_value($signal);
     $element = $signal->data_element($this->default_data_key);
     return set_subelement($element, $this->sublevels, $value);
 }