public static function merge(array ...$configs): array
{
$result = array_shift($configs) ?: [];
while (!empty($configs)) {
foreach (array_shift($configs) as $key => $value) {
if (!is_string($key)) {
throw ExceptionHelper::invalidArrayDefinitionKey($key);
}
if (!isset($result[$key])) {
$result[$key] = $value;
continue;
}
if ($key === ArrayDefinition::CONSTRUCTOR) {
if (!is_array($value)) {
throw ExceptionHelper::incorrectArrayDefinitionConstructorArguments($value);
}
if (!is_array($result[$key])) {
throw ExceptionHelper::incorrectArrayDefinitionConstructorArguments($result[$key]);
}
$result[$key] = self::mergeArguments($result[$key], $value);
continue;
}
if (str_ends_with($key, '()')) {
if (!is_array($value)) {
throw ExceptionHelper::incorrectArrayDefinitionMethodArguments($key, $value);
}
if (!is_array($result[$key])) {
throw ExceptionHelper::incorrectArrayDefinitionMethodArguments($key, $result[$key]);
}
$result[$key] = self::mergeArguments($result[$key], $value);
continue;
}
$result[$key] = $value;
}
}
return $result;
}
Signup or Login in order to comment.