WP_CLI\Utils

format_items()WP-CLI 1.0

Render a collection of items as an ASCII table, JSON, CSV, YAML, list of ids, or count.

Given a collection of items with a consistent data structure:

$items = array(
	array(
		'key'   => 'foo',
		'value'  => 'bar',
	)
);

Render $items as an ASCII table:

WP_CLI\Utils\format_items( 'table', $items, array( 'key', 'value' ) );

# +-----+-------+
# | key | value |
# +-----+-------+
# | foo | bar   |
# +-----+-------+

Or render $items as YAML:

WP_CLI\Utils\format_items( 'yaml', $items, array( 'key', 'value' ) );

# ---
# -
#   key: foo
#   value: bar

Хуков нет.

Возвращает

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

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

format_items( $format, $items, $fields );
$format(строка) (обязательный)
Format to use: 'table', 'json', 'csv', 'yaml', 'ids', 'count'.
$items(массив) (обязательный)
An array of items to output.
$fields(массив|строка) (обязательный)
Named fields for each item of data. Can be array or comma-separated list.

Код format_items() WP-CLI 2.8.0-alpha

function format_items( $format, $items, $fields ) {
	$assoc_args = compact( 'format', 'fields' );
	$formatter  = new Formatter( $assoc_args );
	$formatter->display_items( $items );
}