WP_CLI
Configurator::merge_yml
Load a YAML file of parameters into scope.
Method of the class: Configurator{}
No Hooks.
Returns
null. Nothing (null).
Usage
$Configurator = new Configurator(); $Configurator->merge_yml( $path, $current_alias );
- $path(string) (required)
- Path to YAML file.
- $current_alias
- .
Default: null
Configurator::merge_yml() Configurator::merge yml code WP-CLI 2.13.0-alpha
public function merge_yml( $path, $current_alias = null ) {
$yaml = self::load_yml( $path );
if ( ! empty( $yaml['_']['inherit'] ) ) {
// Refactor with the WP-CLI `Path` class, once it's available.
// See: https://github.com/wp-cli/wp-cli/issues/5007
$inherit_path = is_path_absolute( $yaml['_']['inherit'] )
? $yaml['_']['inherit']
: ( new SplFileInfo( normalize_path( dirname( $path ) . '/' . $yaml['_']['inherit'] ) ) )->getRealPath();
$this->merge_yml( $inherit_path, $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;
}
}
}