CLI_Alias_Command::build_aliases()privateWP-CLI 1.0

Return aliases array.

Метод класса: CLI_Alias_Command{}

No Hooks.

Return

Mixed.

Usage

// private - for code of main (parent) class only
$result = $this->build_aliases( $aliases, $alias, $assoc_args, $is_grouping, $grouping, $is_update );
$aliases(array) (required)
Current aliases data.
$alias(string) (required)
Name of alias.
$assoc_args(array) (required)
Associative arguments.
$is_grouping(true|false) (required)
Check if its a grouping operation.
$grouping(string)
Grouping value.
Default: ''
$is_update(true|false)
Is this an update operation?
Default: false

Code of CLI_Alias_Command::build_aliases() WP-CLI 2.7.0-alpha

private function build_aliases( $aliases, $alias, $assoc_args, $is_grouping, $grouping = '', $is_update = false ) {

	if ( $is_grouping ) {
		$valid_assoc_args = [ 'config', 'grouping' ];
		$invalid_args     = array_diff( array_keys( $assoc_args ), $valid_assoc_args );

		// Check for invalid args.
		if ( ! empty( $invalid_args ) ) {
			$args_info = implode( ',', $invalid_args );
			WP_CLI::error( "--grouping argument works alone. Found invalid arg(s) '$args_info'." );
		}
	}

	if ( $is_update ) {
		$this->validate_alias_type( $aliases, $alias, $assoc_args, $grouping );
	}

	if ( ! $is_grouping ) {
		foreach ( $assoc_args as $key => $value ) {
			if ( strpos( $key, 'set-' ) !== false ) {
				$alias_key_info = explode( '-', $key );
				$alias_key      = empty( $alias_key_info[1] ) ? '' : $alias_key_info[1];
				if ( ! empty( $alias_key ) && ! empty( $value ) ) {
					$aliases[ $alias ][ $alias_key ] = $value;
				}
			}
		}
	} else {

		if ( ! empty( $grouping ) ) {
			$group_alias_list  = explode( ',', $grouping );
			$group_alias       = array_map(
				function ( $current_alias ) {
					return '@' . ltrim( $current_alias, '@' );
				},
				$group_alias_list
			);
			$aliases[ $alias ] = $group_alias;
		}
	}

	return $aliases;
}