Automattic\WooCommerce\Internal\CLI\Migrator\Core

PlatformRegistry::resolve_platformpublicWC 1.0

Determines the platform to use from command arguments, with validation and fallback.

Method of the class: PlatformRegistry{}

No Hooks.

Returns

String. The validated platform slug.

Usage

$PlatformRegistry = new PlatformRegistry();
$PlatformRegistry->resolve_platform( $assoc_args, $default_platform ): string;
$assoc_args(array) (required)
Associative arguments from the command.
$default_platform(string)
The default platform to use if none specified.
Default: 'shopify'

PlatformRegistry::resolve_platform() code WC 10.7.0

public function resolve_platform( array $assoc_args, string $default_platform = 'shopify' ): string {
	$platform = $assoc_args['platform'] ?? null;

	if ( empty( $platform ) ) {
		$platform              = $default_platform;
		$platform_display_name = $this->get_platform_display_name( $platform );
		WP_CLI::log( "Platform not specified, using default: '{$platform_display_name}'." );
	}

	// Validate the platform exists.
	if ( ! $this->get_platform( $platform ) ) {
		$available_platforms = array_keys( $this->get_platforms() );
		if ( empty( $available_platforms ) ) {
			WP_CLI::error( 'No platforms are currently registered. Please ensure platform plugins are installed and activated.' );
		} else {
			WP_CLI::error(
				sprintf(
					"Platform '%s' is not registered. Available platforms: %s",
					$platform,
					implode( ', ', $available_platforms )
				)
			);
		}
	}

	return $platform;
}