| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\Mcp\Abilities\Appliers\V3\Converter; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
/** |
| 10 |
* Immutable per-node conversion metadata: everything a converter needs to look up |
| 11 |
* the mapping for a rule without recomputing it per declaration. |
| 12 |
*/ |
| 13 |
class V3_Context_Meta { |
| 14 |
|
| 15 |
private string $widget_type; |
| 16 |
private array $widget_config; |
| 17 |
private array $overrides; |
| 18 |
private array $generic_index; |
| 19 |
|
| 20 |
public function __construct( string $widget_type, array $widget_config, array $overrides, array $generic_index ) { |
| 21 |
$this->widget_type = $widget_type; |
| 22 |
$this->widget_config = $widget_config; |
| 23 |
$this->overrides = $overrides; |
| 24 |
$this->generic_index = $generic_index; |
| 25 |
} |
| 26 |
|
| 27 |
public function widget_type(): string { |
| 28 |
return $this->widget_type; |
| 29 |
} |
| 30 |
|
| 31 |
public function widget_config(): array { |
| 32 |
return $this->widget_config; |
| 33 |
} |
| 34 |
|
| 35 |
public function overrides(): array { |
| 36 |
return $this->overrides; |
| 37 |
} |
| 38 |
|
| 39 |
public function generic_index(): array { |
| 40 |
return $this->generic_index; |
| 41 |
} |
| 42 |
|
| 43 |
public function controls(): array { |
| 44 |
$controls = $this->widget_config['controls'] ?? []; |
| 45 |
|
| 46 |
return is_array( $controls ) ? $controls : []; |
| 47 |
} |
| 48 |
|
| 49 |
public function has_control( string $key ): bool { |
| 50 |
return array_key_exists( $key, $this->controls() ); |
| 51 |
} |
| 52 |
|
| 53 |
public function match_key( string $property, ?string $state ): string { |
| 54 |
return null === $state ? $property : $property . '@' . $state; |
| 55 |
} |
| 56 |
|
| 57 |
public function get_override( string $property, ?string $state ): ?array { |
| 58 |
$key = $this->match_key( $property, $state ); |
| 59 |
|
| 60 |
return $this->overrides[ $key ] ?? null; |
| 61 |
} |
| 62 |
|
| 63 |
public function get_generic_rule( string $property, ?string $state ): ?array { |
| 64 |
$key = $this->match_key( $property, $state ); |
| 65 |
|
| 66 |
return $this->generic_index[ $key ] ?? null; |
| 67 |
} |
| 68 |
} |
| 69 |
|