WP_CLI

Formatter::display_items()publicWP-CLI 1.0

Display multiple items according to the output arguments.

Method of the class: Formatter{}

No Hooks.

Return

null. Nothing.

Usage

$Formatter = new Formatter();
$Formatter->display_items( $items, $ascii_pre_colorized );
$items(array|Iterator) (required)
The items to display.
$ascii_pre_colorized(true|false|array)
A boolean or an array of booleans to pass to format() if items in the table are pre-colorized.
Default: false

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

public function display_items( $items, $ascii_pre_colorized = false ) {
	if ( $this->args['field'] ) {
		$this->show_single_field( $items, $this->args['field'] );
	} else {
		if ( in_array( $this->args['format'], [ 'csv', 'json', 'table' ], true ) ) {
			$item = is_array( $items ) && ! empty( $items ) ? array_shift( $items ) : false;
			if ( $item && ! empty( $this->args['fields'] ) ) {
				foreach ( $this->args['fields'] as &$field ) {
					$field = $this->find_item_key( $item, $field );
				}
				array_unshift( $items, $item );
			}
		}

		if ( in_array( $this->args['format'], [ 'table', 'csv' ], true ) ) {
			if ( $items instanceof Iterator ) {
				$items = Utils\iterator_map( $items, [ $this, 'transform_item_values_to_json' ] );
			} else {
				$items = array_map( [ $this, 'transform_item_values_to_json' ], $items );
			}
		}

		$this->format( $items, $ascii_pre_colorized );
	}
}