WP_CLI

Formatter::display_items()publicWP-CLI 1.0

Display multiple items according to the output arguments.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

$Formatter = new Formatter();
$Formatter->display_items( $items, $ascii_pre_colorized );
$items(массив|Iterator) (обязательный)
The items to display.
$ascii_pre_colorized(true|false|массив)
A boolean or an array of booleans to pass to format() if items in the table are pre-colorized.
По умолчанию: false

Код Formatter::display_items() 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 );
	}
}