Find the existing defined aliases so they can be merged with new ones.

@param string      $currentGroup
@param string|null $previousGroup

@return array
The aliases, with their group prefixes removed.
554254
protected function getExistingAliases($currentGroup, $previousGroup = null)
    {
        $aliases = [];
        foreach (array_filter([$currentGroup, $previousGroup]) as $groupName) {
            foreach ($this->drush->getAliases($groupName) as $name => $alias) {
                // Remove the group prefix from the alias name.
                $name = ltrim($name, '@');
                if (strpos($name, $groupName . '.') === 0) {
                    $name = substr($name, strlen($groupName . '.'));
                }

                $aliases[$name] = $alias;
            }
        }

        return $aliases;
    }
826051
public static function merge($currentArray, $newArray)
    {
        $mergeIdentifier = '__APPEND__';

        if (is_array($currentArray) && !is_array($newArray)) {
            return $currentArray;
        } else if (!is_array($currentArray) && is_array($newArray)) {
            return $newArray;
        } else if ((!is_array($currentArray) || empty($currentArray)) && (!is_array($newArray) || empty($newArray))) {
            return array();
        }

        foreach ($newArray as $newName => $newValue) {

            if (is_array($newValue) && array_key_exists($newName, $currentArray) && is_array($currentArray[$newName])) {

                // check __APPEND__ identifier
                $appendKey = array_search($mergeIdentifier, $newValue, true);
                if ($appendKey !== false) {
                    unset($newValue[$appendKey]);
                    $newValue = array_merge($currentArray[$newName], $newValue);
                } else if (!static::isSingleArray($newValue) || !static::isSingleArray($currentArray[$newName])) {
                    $newValue = static::merge($currentArray[$newName], $newValue);
                }

            }

            //check if exists __APPEND__ identifier and remove its
            if (!isset($currentArray[$newName]) && is_array($newValue)) {
                $newValue = static::unsetInArrayByValue($mergeIdentifier, $newValue);
            }

            $currentArray[$newName] = $newValue;
        }

        return $currentArray;
    }
593733
public function getAliases($extension = null)
    {
        if ($extension === null) {
            return $this->aliases;
        }
        elseif (isset($this->aliases[$extension])) {
            return $this->aliases[$extension];
        }
        else {
            return null;
        }
    }
316992
public static function getKeys($group)
    {
        self::loadKeys();
        self::$keys[$group] = isset(self::$keys[$group]) ? self::$keys[$group] : [];

        return self::$keys[$group];
    }
505275
public static function mergePrefixData($data, $prefixData)
    {
        $prefixGroups = $prefixData['prefix-groups'];

        foreach ($data["partitions"] as $index => $partition) {
            foreach ($prefixGroups as $current => $old) {
                $serviceData = Env::search("services.{$current}", $partition);
                if (!empty($serviceData)) {
                    foreach ($old as $prefix) {
                        if (empty(Env::search("services.{$prefix}", $partition))) {
                            $data["partitions"][$index]["services"][$prefix] = $serviceData;
                        }
                    }
                }
            }
        }

        return $data;
    }
993046
public function merge_yml( $path, $current_alias = null ) {
		$yaml = self::load_yml( $path );
		if ( ! empty( $yaml['_']['inherit'] ) ) {
			$this->merge_yml( $yaml['_']['inherit'], $current_alias );
		}
		// Prepare the base path for absolutized alias paths
		$yml_file_dir = $path ? dirname( $path ) : false;
		foreach ( $yaml as $key => $value ) {
			if ( preg_match( '#' . self::ALIAS_REGEX . '#', $key ) ) {
				$this->aliases[ $key ] = array();
				$is_alias              = false;
				foreach ( self::$alias_spec as $i ) {
					if ( isset( $value[ $i ] ) ) {
						if ( 'path' === $i && ! isset( $value['ssh'] ) ) {
							self::absolutize( $value[ $i ], $yml_file_dir );
						}
						$this->aliases[ $key ][ $i ] = $value[ $i ];
						$is_alias                    = true;
					}
				}
				// If it's not an alias, it might be a group of aliases
				if ( ! $is_alias && is_array( $value ) ) {
					$alias_group = array();
					foreach ( $value as $i => $k ) {
						if ( preg_match( '#' . self::ALIAS_REGEX . '#', $k ) ) {
							$alias_group[] = $k;
						}
					}
					$this->aliases[ $key ] = $alias_group;
				}
			} elseif ( ! isset( $this->spec[ $key ] ) || false === $this->spec[ $key ]['file'] ) {
				if ( isset( $this->extra_config[ $key ] )
					&& ! empty( $yaml['_']['merge'] )
					&& is_array( $this->extra_config[ $key ] )
					&& is_array( $value ) ) {
					$this->extra_config[ $key ] = array_merge( $this->extra_config[ $key ], $value );
				} else {
					$this->extra_config[ $key ] = $value;
				}
			} elseif ( $this->spec[ $key ]['multiple'] ) {
				self::arrayify( $value );
				$this->config[ $key ] = array_merge( $this->config[ $key ], $value );
			} else {
				if ( $current_alias && in_array( $key, self::$alias_spec, true ) ) {
					continue;
				}
				$this->config[ $key ] = $value;
			}
		}
	}
743274
public function getPreviousSibling(Branch $branch, Branch $currentBranch)
    {
        $current = null;
        $previousSibiling = null;

        foreach ($branch->getChildren() as $node) {
            if ($node->getNodeId() === $currentBranch->getNodeId()) {
                $current = $node;
            }
            if (!$current) {
                $previousSibiling = $node;
            }
            if ($previousSibiling && $current) {
                break;
            }
        }

        return $previousSibiling;
    }
248146
public function resolveToSubstitutionGroup( $substitutionGroup, $candidates )
	{
		// Check the potential candidates are valid
		if ( ! is_array( $candidates ) || ! count( $candidates ) ) return false;

		if ( $substitutionGroup instanceof QName )
		{
			$substitutionGroup = "{$substitutionGroup->prefix}:{$substitutionGroup->localName}";
		}
		else if ( ! is_string( $substitutionGroup ) ) return false;

		// Is the $substitutionGroup already in $candidates
		if ( in_array( $substitutionGroup, $candidates ) ) return true;

		// If its not then look to see if there are ancestral elements
		if ( ! isset( $this->elements[ $substitutionGroup ] ) ) return false;

		$element = $this->elements[ $substitutionGroup ];
		if ( isset( $element['substitutionGroup'] ) )
		{
			// There are so repeat the test with the ancestor element
			return $this->resolveToSubstitutionGroup( $element['substitutionGroup'], $candidates );
		}
		else
		{
			return false;
		}
	}
73159
public function rename($currentKey, $newKey)
    {
        if ($this->has($currentKey)) {
            $this->set($newKey, $this->proxy->{$currentKey})->remove($currentKey);
        }

        return $this;
    }
384900
public function group(string $prefix, \Closure $callback, array $opts = [])
    {
        $previousGroupPrefix = $this->currentGroupPrefix;
        $this->currentGroupPrefix = $previousGroupPrefix . '/' . \trim($prefix, '/');

        $previousGroupOption = $this->currentGroupOption;
        $this->currentGroupOption = $opts;

        $callback($this);

        $this->currentGroupPrefix = $previousGroupPrefix;
        $this->currentGroupOption = $previousGroupOption;
    }
818319
public function getCurrentUserPrincipals()
    {
        $currentUser = $this->getCurrentUserPrincipal();

        if (is_null($currentUser)) {
            return [];
        }

        return array_merge(
            [$currentUser],
            $this->getPrincipalMembership($currentUser)
        );
    }
677299
private function getParentGroup($matchNumber, $previousRound)
    {
        $parentIndex = intval(($matchNumber + 1) / 2);
        $parent = $previousRound->get($parentIndex - 1);

        return $parent;
    }
356077
public static function getConversionGroupUnits($group = NULL) {
		$conversionGroups = array();
		foreach(self::$_conversionUnits as $conversionUnit => $conversionGroup) {
			if ((is_null($group)) || ($conversionGroup['Group'] == $group)) {
				$conversionGroups[$conversionGroup['Group']][] = $conversionUnit;
			}
		}
		return $conversionGroups;
	}
1082677
public static function createUniqueName($group = null)
    {
        $group = empty($group) ? self::DEFAULT_GROUP : $group;
        $group = Uuid::uuid3(self::GROUP_NS, $group)->toString();
        $name = Uuid::uuid4()->toString();

        return $group.'-'.$name;
    }
616359
function getDefaultUsergroup()
    {
        $usergroups = Groups::get($this->getJname(), true);

        $groups = array();
        if ($usergroups !== null) {
	        $list = $this->getUsergroupList();
	        foreach ($list as $group) {
		        if(in_array($group->id, $usergroups)){
			        $groups[] = $group->name;
		        }
	        }
        }
        return $groups;
    }
1032920
public function group($group, $context) {
		if (!$group) {
			return null;
		}
		$self = $this;
		$model = $context->model();
		$alias = $context->alias();

		$escaped = array_map(function($field) use ($self, $model, $alias) {
			if (!$model || !$model::schema($field)) {
				return $self->name($field);
			}
			return $self->name($alias) . '.' . $self->name($field);
		}, (array) $group);

		return 'GROUP BY ' .  join(', ', $escaped);
	}
773768
public function getServiceTypes($group = null)
    {
        ksort($this->types, SORT_NATURAL); // sort by name for display
        if (!empty($group)) {
            if (!empty($group) && !is_array($group)) {
                $group = array_map('trim', explode(',', trim($group, ',')));
            }
            $group = array_map('strtolower', (array)$group);
            $types = [];
            foreach ($this->types as $type) {
                if (in_array(strtolower($type->getGroup()), $group)) {
                    $types[$type->getName()] = $type;
                }
            }

            return $types;
        }

        return $this->types;
    }