/var/www/html_it/wp-content/plugins/woocommerce/src/Internal/CLI/Migrator/Commands/SetupCommand.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php

declare( strict_types=);

namespace 
Automattic\WooCommerce\Internal\CLI\Migrator\Commands;

use 
Automattic\WooCommerce\Internal\CLI\Migrator\Core\CredentialManager;
use 
Automattic\WooCommerce\Internal\CLI\Migrator\Core\PlatformRegistry;
use 
WP_CLI;

/**
 * The command for interactively setting up platform credentials.
 */
class SetupCommand {

    
/**
     * The credential manager.
     *
     * @var CredentialManager
     */
    
private CredentialManager $credential_manager;

    
/**
     * The platform registry.
     *
     * @var PlatformRegistry
     */
    
private PlatformRegistry $platform_registry;

    
/**
     * Initialize the command with its dependencies.
     *
     * @param CredentialManager $credential_manager The credential manager.
     * @param PlatformRegistry  $platform_registry  The platform registry.
     *
     * @internal
     */
    
final public function initCredentialManager $credential_managerPlatformRegistry $platform_registry ): void {
        
$this->credential_manager $credential_manager;
        
$this->platform_registry  $platform_registry;
    }

    
/**
     * Sets up the credentials for a given platform.
     *
     * ## OPTIONS
     *
     * [--platform=<platform>]
     * : The platform to set up credentials for. Defaults to 'shopify'.
     *
     * ## EXAMPLES
     *
     *     wp wc migrate setup
     *
     * @param array $args       Positional arguments.
     * @param array $assoc_args Associative arguments.
     */
    
public function __invoke( array $args, array $assoc_args ) {
        
// Resolve and validate the platform.
        
$platform $this->platform_registry->resolve_platform$assoc_args );

        
// Get platform-specific credential fields and set them up.
        
$required_fields $this->platform_registry->get_platform_credential_fields$platform );
        if ( empty( 
$required_fields ) ) {
            
WP_CLI::error"The platform '{$platform}' does not have configured credential fields." );
        }

        
$this->credential_manager->setup_credentials$platform$required_fields );
        
WP_CLI::success'Credentials saved successfully.' );
    }
}