schemas
1 year ago
ActivatePlugin.php
1 year ago
ActivateTheme.php
1 year ago
InstallPlugin.php
1 year ago
InstallTheme.php
1 year ago
RunSql.php
1 year ago
SetSiteOptions.php
1 year ago
Step.php
1 year ago
InstallPlugin.php
113 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\WooCommerce\Blueprint\Steps; |
| 4 | |
| 5 | /** |
| 6 | * Class InstallPlugin |
| 7 | * |
| 8 | * This class represents a step in the installation process of a WooCommerce plugin. |
| 9 | * It includes methods to prepare the data for the plugin installation step and to provide |
| 10 | * the schema for the JSON representation of this step. |
| 11 | * |
| 12 | * @package Automattic\WooCommerce\Blueprint\Steps |
| 13 | */ |
| 14 | class InstallPlugin extends Step { |
| 15 | /** |
| 16 | * The slug of the plugin to be installed. |
| 17 | * |
| 18 | * @var string The slug of the plugin to be installed. |
| 19 | */ |
| 20 | private string $slug; |
| 21 | |
| 22 | /** |
| 23 | * The resource URL or path to the plugin's ZIP file. |
| 24 | * |
| 25 | * @var string The resource URL or path to the plugin's ZIP file. |
| 26 | */ |
| 27 | private string $resource; |
| 28 | |
| 29 | /** |
| 30 | * Additional options for the plugin installation. |
| 31 | * |
| 32 | * @var array Additional options for the plugin installation. |
| 33 | */ |
| 34 | private array $options; |
| 35 | |
| 36 | /** |
| 37 | * InstallPlugin constructor. |
| 38 | * |
| 39 | * @param string $slug The slug of the plugin to be installed. |
| 40 | * @param string $resource The resource URL or path to the plugin's ZIP file. |
| 41 | * @param array $options Additional options for the plugin installation. |
| 42 | */ |
| 43 | // phpcs:ignore |
| 44 | public function __construct( $slug, $resource, array $options = array() ) { |
| 45 | $this->slug = $slug; |
| 46 | $this->resource = $resource; |
| 47 | $this->options = $options; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Prepares an associative array for JSON encoding. |
| 52 | * |
| 53 | * @return array Array representing this installation step. |
| 54 | */ |
| 55 | public function prepare_json_array(): array { |
| 56 | return array( |
| 57 | 'step' => static::get_step_name(), |
| 58 | 'pluginData' => array( |
| 59 | 'resource' => $this->resource, |
| 60 | 'slug' => $this->slug, |
| 61 | ), |
| 62 | 'options' => $this->options, |
| 63 | ); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Returns the schema for the JSON representation of this step. |
| 68 | * |
| 69 | * @param int $version The version of the schema to return. |
| 70 | * @return array The schema array. |
| 71 | */ |
| 72 | public static function get_schema( int $version = 1 ): array { |
| 73 | return array( |
| 74 | 'type' => 'object', |
| 75 | 'properties' => array( |
| 76 | 'step' => array( |
| 77 | 'type' => 'string', |
| 78 | 'enum' => array( static::get_step_name() ), |
| 79 | ), |
| 80 | 'pluginData' => array( |
| 81 | 'anyOf' => array( |
| 82 | require __DIR__ . '/schemas/definitions/VFSReference.php', |
| 83 | require __DIR__ . '/schemas/definitions/LiteralReference.php', |
| 84 | require __DIR__ . '/schemas/definitions/CorePluginReference.php', |
| 85 | require __DIR__ . '/schemas/definitions/CoreThemeReference.php', |
| 86 | require __DIR__ . '/schemas/definitions/UrlReference.php', |
| 87 | require __DIR__ . '/schemas/definitions/GitDirectoryReference.php', |
| 88 | require __DIR__ . '/schemas/definitions/DirectoryLiteralReference.php', |
| 89 | ), |
| 90 | ), |
| 91 | 'options' => array( |
| 92 | 'type' => 'object', |
| 93 | 'properties' => array( |
| 94 | 'activate' => array( |
| 95 | 'type' => 'boolean', |
| 96 | ), |
| 97 | ), |
| 98 | ), |
| 99 | ), |
| 100 | 'required' => array( 'step', 'pluginData' ), |
| 101 | ); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Returns the name of this step. |
| 106 | * |
| 107 | * @return string The step name. |
| 108 | */ |
| 109 | public static function get_step_name(): string { |
| 110 | return 'installPlugin'; |
| 111 | } |
| 112 | } |
| 113 |