WP_CLI

Formatter::__construct()publicWP-CLI 1.0

Method of the class: Formatter{}

No Hooks.

Return

null. Nothing.

Usage

$Formatter = new Formatter();
$Formatter->__construct( $assoc_args, $fields, $prefix );
$assoc_args(array) (required) (passed by reference — &)
Output format arguments.
$fields(array)
Fields to display of each item.
Default: null
$prefix(string|true|false)
Check if fields have a standard prefix. False indicates empty prefix.
Default: false

Formatter::__construct() code WP-CLI 2.8.0-alpha

public function __construct( &$assoc_args, $fields = null, $prefix = false ) {
	$format_args = [
		'format' => 'table',
		'fields' => $fields,
		'field'  => null,
	];

	foreach ( [ 'format', 'fields', 'field' ] as $key ) {
		if ( isset( $assoc_args[ $key ] ) ) {
			$format_args[ $key ] = $assoc_args[ $key ];
			unset( $assoc_args[ $key ] );
		}
	}

	if ( ! is_array( $format_args['fields'] ) ) {
		$format_args['fields'] = explode( ',', $format_args['fields'] );
	}

	$format_args['fields'] = array_map( 'trim', $format_args['fields'] );

	$this->args   = $format_args;
	$this->prefix = $prefix;
}