/var/www/html_it/wp-content/plugins/woocommerce/src/Internal/CLI/Migrator/Commands/ListCommand.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php

declare( strict_types=);

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

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

/**
 * Lists all registered migration platforms.
 */
class ListCommand {

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

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

    
/**
     * Lists all registered migration platforms.
     *
     * ## EXAMPLES
     *
     *     $ wp wc migrate list
     *
     * @param array $args       The positional arguments (unused).
     * @param array $assoc_args The associative arguments (unused).
     *
     * @return void
     */
    
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' )
        );
    }
}