/var/www/html_sp/wp-content/plugins/woocommerce/vendor/woocommerce/blueprint/src/Cli/ExportCli.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
<?php

namespace Automattic\WooCommerce\Blueprint\Cli;

use 
Automattic\WooCommerce\Blueprint\ExportSchema;
use 
Automattic\WooCommerce\Blueprint\ZipExportedSchema;

/**
 * Class ExportCli
 *
 * This class handles the CLI commands for exporting schemas.
 *
 * @package Automattic\WooCommerce\Blueprint\Cli
 */
class ExportCli {
    
/**
     * The path where the exported schema will be saved.
     *
     * @var string The path where the exported schema will be saved.
     */
    
private string $save_to;

    
/**
     * ExportCli constructor.
     *
     * @param string $save_to The path where the exported schema will be saved.
     */
    
public function __construct$save_to ) {
        
$this->save_to $save_to;
    }

    
/**
     * Run the export process.
     *
     * @param array $args The arguments for the export process.
     */
    
public function run$args = array() ) {
        
$export_as_zip = isset( $args['format'] ) && 'zip' === $args['format'];
        if ( ! isset( 
$args['steps'] ) ) {
            
$args['steps'] = array();
        }

        
$exporter = new ExportSchema();

        
$schema $exporter->export$args['steps'], $export_as_zip );

        if ( 
$export_as_zip ) {
            
$zip_exported_schema = new ZipExportedSchema$schema );
            
$this->save_to       $zip_exported_schema->zip();
            
\WP_CLI::success"Exported zip to {$this->save_to});
        } else {
            
// phpcs:ignore
            
$save file_put_contents$this->save_tojson_encode$schemaJSON_PRETTY_PRINT ) );
            if ( 
false === $save ) {
                
\WP_CLI::error"Failed to save to {$this->save_to});
            } else {
                
\WP_CLI::success"Exported JSON to {$this->save_to});
            }
        }
    }
}