WP_CLI

Configurator::merge_yml()publicWP-CLI 1.0

Load a YAML file of parameters into scope.

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

Хуков нет.

Возвращает

null. Ничего.

Использование

$Configurator = new Configurator();
$Configurator->merge_yml( $path, $current_alias );
$path(строка) (обязательный)
Path to YAML file.
$current_alias **
-
По умолчанию: null

Код Configurator::merge_yml() WP-CLI 2.8.0-alpha

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 ] = [];
			$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 = [];
				foreach ( $value as $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;
		}
	}
}