function __construct($init = NULL, $aliases = NULL, $name = NULL) { $this->key2values = []; $this->value2key = []; $this->all_sub_keys = []; $this->level = []; $this->simple_keys = []; $this->recursive_keys = []; $this->name = $name; if ($aliases === NULL) { $aliases = []; } $this->aliases = $aliases; #echo "\$init:\n"; #var_dump($init); if ($init !== NULL) { foreach ($init as $k => $v) { if (!is_array($v)) { _die("bad type, not array"); } if (is_vec($v)) { $this->simple_keys[] = $k; register2($this, $k, $v); } else { $this->recursive_keys[] = $k; foreach ($v as $_ => &$v_) { register($this, $k, $_); #echo "\$v_:\n"; #var_dump($v_); if (!ISDEPATH($v_)) { $v_ = DEPATH($v_, $aliases); } $this->all_sub_keys = array_merge($this->all_sub_keys, $v_->all_sub_keys); register3($this, $v_->key2values); } } $this->level[$k] = $v; } } # Sort and remove duplicates $this->all_sub_keys = array_values(array_unique($this->all_sub_keys)); foreach (array_keys($this->key2values) as $k) { $this->key2values[$k] = array_unique($this->key2values[$k]); } }
function make_depaths(&$result, &$depaths, &$parts, $lang = NULL) { foreach ($depaths as $key => &$depath) { $duo = [[], []]; # Add keys to populate the depath via duo[] foreach ($depath as $_) { if (is_scalar($_)) { add_key($duo, $_, $parts, $result); } else { copy_onto($duo[0], reduced_values($_, $parts, $duo[1])[0]); } } # link depath into result, update caller's record of the depaths $depath = $result[$key] = DEPATH($duo[0], $duo[1], "{$lang}/{$key}"); } return $result; }