private function replaceTypes($raml, $types, $path, $name, $parentKey = null)
{
if (strpos($path, '/') !== 0 || !is_array($raml)) {
return $raml;
}
$newArray = [];
foreach ($raml as $key => $value) {
if ($key === 'type' && strpos($parentKey, '/') === 0) {
$type = [];
$traitVariables = ['resourcePath' => $path, 'resourcePathName' => $name];
if (is_array($value)) {
$traitVariables = array_merge($traitVariables, current($value));
$traitName = key($value);
$type = $this->applyTraitVariables($traitVariables, $types[$traitName]);
} elseif (isset($types[$value])) {
$type = $this->applyTraitVariables($traitVariables, $types[$value]);
}
$newArray = array_replace_recursive($newArray, $this->replaceTypes($type, $types, $path, $name, $key));
} else {
$newName = $name;
if (strpos($key, '/') === 0 && !preg_match('/^\\/\\{.+\\}$/', $key)) {
$newName = isset($value['displayName']) ? $value['displayName'] : substr($key, 1);
}
$newValue = $this->replaceTypes($value, $types, $path, $newName, $key);
if (isset($newArray[$key]) && is_array($newArray[$key])) {
$newArray[$key] = array_replace_recursive($newArray[$key], $newValue);
} else {
$newArray[$key] = $newValue;
}
}
}
return $newArray;
}