private function process(array $arr)
{
$res = [];
foreach ($arr as $key => $val) {
if (is_string($key) && substr($key, -1) === self::PREVENT_MERGING) {
if (!is_array($val) && $val !== NULL) {
throw new Nette\InvalidStateException("Replacing operator is available only for arrays, item '{$key}' is not array.");
}
$key = substr($key, 0, -1);
$val[Helpers::EXTENDS_KEY] = Helpers::OVERWRITE;
} elseif (is_string($key) && preg_match('#^(\\S+)\\s+' . self::INHERITING_SEPARATOR . '\\s+(\\S+)\\z#', $key, $matches)) {
if (!is_array($val) && $val !== NULL) {
throw new Nette\InvalidStateException("Inheritance operator is available only for arrays, item '{$key}' is not array.");
}
list(, $key, $val[Helpers::EXTENDS_KEY]) = $matches;
if (isset($res[$key])) {
throw new Nette\InvalidStateException("Duplicated key '{$key}'.");
}
}
if (is_array($val)) {
$val = $this->process($val);
} elseif ($val instanceof Neon\Entity) {
if ($val->value === Neon\Neon::CHAIN) {
$tmp = NULL;
foreach ($this->process($val->attributes) as $st) {
$tmp = new Statement($tmp === NULL ? $st->getEntity() : [$tmp, ltrim($st->getEntity(), ':')], $st->arguments);
}
$val = $tmp;
} else {
$tmp = $this->process([$val->value]);
$val = new Statement($tmp[0], $this->process($val->attributes));
}
}
$res[$key] = $val;
}
return $res;
}