Automattic\WooCommerce\Internal\CLI\Migrator\Commands

ListCommand::__invokepublicWC 1.0

Lists all registered migration platforms.

EXAMPLES

$ wp wc migrate list

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

Хуков нет.

Возвращает

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

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

$ListCommand = new ListCommand();
$ListCommand->__invoke( $args, $assoc_args ): void;
$args(массив) (обязательный)
The positional arguments (unused).
$assoc_args(массив) (обязательный)
The associative arguments (unused).

Код ListCommand::__invoke() WC 11.1.0

public function __invoke( array $args, array $assoc_args ): void {
	// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
	unset( $args, $assoc_args );

	$platforms = $this->platform_registry->get_platforms();

	if ( empty( $platforms ) ) {
		WP_CLI::line( 'No migration platforms are registered.' );
		return;
	}

	$formatted_items = array();
	$platform_count  = count( $platforms );
	$current_index   = 0;

	foreach ( $platforms as $id => $details ) {
		$formatted_items[] = array(
			'id'      => $id,
			'name'    => $details['name'] ?? '',
			'fetcher' => $details['fetcher'] ?? '',
			'mapper'  => $details['mapper'] ?? '',
		);

		// Add separator row between platforms (but not after the last one).
		++$current_index;
		if ( $current_index < $platform_count ) {
			$formatted_items[] = array(
				'id'      => str_repeat( '-', 20 ),
				'name'    => str_repeat( '-', 25 ),
				'fetcher' => str_repeat( '-', 30 ),
				'mapper'  => str_repeat( '-', 30 ),
			);
		}
	}

	WP_CLI\Utils\format_items(
		'table',
		$formatted_items,
		array( 'id', 'name', 'fetcher', 'mapper' )
	);
}