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
Step.php
69 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\WooCommerce\Blueprint\Steps; |
| 4 | |
| 5 | /** |
| 6 | * Abstract class Step |
| 7 | * |
| 8 | * This class defines the structure for a Step that requires arguments to perform an action. |
| 9 | * You can think it as a function described in JSON format. |
| 10 | * |
| 11 | * A Step should also be capable of returning formatted data that can be imported later. |
| 12 | * Additionally, a Step can validate data. |
| 13 | */ |
| 14 | abstract class Step { |
| 15 | /** |
| 16 | * Meta values for the step. |
| 17 | * |
| 18 | * @var array $meta_values |
| 19 | */ |
| 20 | protected array $meta_values = array(); |
| 21 | |
| 22 | /** |
| 23 | * Get the step name. |
| 24 | * |
| 25 | * @return string |
| 26 | */ |
| 27 | abstract public static function get_step_name(): string; |
| 28 | |
| 29 | /** |
| 30 | * Get the schema for this step. |
| 31 | * |
| 32 | * @param int $version The schema version. |
| 33 | * |
| 34 | * @return array |
| 35 | */ |
| 36 | abstract public static function get_schema( int $version = 1 ): array; |
| 37 | |
| 38 | /** |
| 39 | * Prepare the JSON array for this step. |
| 40 | * |
| 41 | * @return array The JSON array for the step. |
| 42 | */ |
| 43 | abstract public function prepare_json_array(): array; |
| 44 | |
| 45 | /** |
| 46 | * Set meta values for the step. |
| 47 | * |
| 48 | * @param array $meta_values The meta values. |
| 49 | * |
| 50 | * @return void |
| 51 | */ |
| 52 | public function set_meta_values( array $meta_values ) { |
| 53 | $this->meta_values = $meta_values; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Get the JSON array for the step. |
| 58 | * |
| 59 | * @return mixed |
| 60 | */ |
| 61 | public function get_json_array() { |
| 62 | $json_array = $this->prepare_json_array(); |
| 63 | if ( ! empty( $this->meta_values ) ) { |
| 64 | $json_array['meta'] = $this->meta_values; |
| 65 | } |
| 66 | return $json_array; |
| 67 | } |
| 68 | } |
| 69 |