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 = [];

                $typeVariables = ['resourcePath' => $path, 'resourcePathName' => $name];

                if (\is_array($value)) {
                    $typeVariables = \array_merge($typeVariables, \current($value));
                    $typeName = \key($value);
                    $type = $this->applyVariables($typeVariables, $types[$typeName]);
                } elseif (isset($types[$value])) {
                    $type = $this->applyVariables($typeVariables, $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);

                $newArray[$key] = isset($newArray[$key]) && \is_array($newArray[$key]) ? \array_replace_recursive($newArray[$key], $newValue) : $newValue;
            }
        }

        return $newArray;
    }
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 = [];

                $typeVariables = ['resourcePath' => $path, 'resourcePathName' => $name];

                if (\is_array($value)) {
                    $typeVariables = \array_merge($typeVariables, \current($value));
                    $typeName = \key($value);
                    $type = $this->applyVariables($typeVariables, $types[$typeName]);
                } elseif (isset($types[$value])) {
                    $type = $this->applyVariables($typeVariables, $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);

                $newArray[$key] = isset($newArray[$key]) && \is_array($newArray[$key]) ? \array_replace_recursive($newArray[$key], $newValue) : $newValue;
            }
        }

        return $newArray;
    }
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 = [ ] ; $ typeVariables = [ 'resourcePath' => $ path , 'resourcePathName' => $ name ] ; if ( \ is_array ( $ value ) ) { $ typeVariables = \ array_merge ( $ typeVariables , \ current ( $ value ) ) ; $ typeName = \ key ( $ value ) ; $ type = $ this -> applyVariables ( $ typeVariables , $ types [ $ typeName ] ) ; } elseif ( isset ( $ types [ $ value ] ) ) { $ type = $ this -> applyVariables ( $ typeVariables , $ 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 ) ; $ newArray [ $ key ] = isset ( $ newArray [ $ key ] ) && \ is_array ( $ newArray [ $ key ] ) ? \ array_replace_recursive ( $ newArray [ $ key ] , $ newValue ) : $ newValue ; } } return $ newArray ; }
Insert the types into the RAML file

@param string|array $raml
@param array $types
@param string $path
@param string $name
@param string|null $parentKey
@return array
Insert the types into the RAML file