| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\App\Modules\ImportExportCustomization; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
/** |
| 10 |
* Shared import context for design-system entities (global classes, global variables). |
| 11 |
* Resolves the import flow ('settings' vs 'design-system') and its conflict resolution strategy. |
| 12 |
*/ |
| 13 |
class Design_System_Import_Context { |
| 14 |
/** |
| 15 |
* Either 'settings', 'design-system' or null. |
| 16 |
* |
| 17 |
* @var string|null |
| 18 |
*/ |
| 19 |
private ?string $include_key; |
| 20 |
|
| 21 |
private function __construct( ?string $include_key ) { |
| 22 |
$this->include_key = $include_key; |
| 23 |
} |
| 24 |
|
| 25 |
public static function from_data( array $data ): self { |
| 26 |
$include = $data['include'] ?? []; |
| 27 |
|
| 28 |
if ( in_array( 'settings', $include, true ) ) { |
| 29 |
return new self( 'settings' ); |
| 30 |
} |
| 31 |
|
| 32 |
if ( in_array( 'design-system', $include, true ) ) { |
| 33 |
return new self( 'design-system' ); |
| 34 |
} |
| 35 |
|
| 36 |
return new self( null ); |
| 37 |
} |
| 38 |
|
| 39 |
public function is_included(): bool { |
| 40 |
return null !== $this->include_key; |
| 41 |
} |
| 42 |
|
| 43 |
public function is_settings(): bool { |
| 44 |
return 'settings' === $this->include_key; |
| 45 |
} |
| 46 |
|
| 47 |
public function is_design_system(): bool { |
| 48 |
return 'design-system' === $this->include_key; |
| 49 |
} |
| 50 |
|
| 51 |
public function resolve_conflict_resolution( array $data, string $override_all_key ): string { |
| 52 |
if ( $this->is_settings() ) { |
| 53 |
return ! empty( $data['customization']['settings'][ $override_all_key ] ) |
| 54 |
? 'override-all' |
| 55 |
: 'merge'; |
| 56 |
} |
| 57 |
|
| 58 |
if ( $this->is_design_system() ) { |
| 59 |
return $data['customization']['design-system']['conflict_resolution'] ?? 'skip'; |
| 60 |
} |
| 61 |
|
| 62 |
throw new \Exception( 'Cannot resolve conflict resolution without a valid include include_key.' ); |
| 63 |
} |
| 64 |
} |
| 65 |
|