| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\AtomicWidgets\CssConverter; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; // Exit if accessed directly. |
| 7 |
} |
| 8 |
|
| 9 |
abstract class Property_Converter_Base implements Property_Converter { |
| 10 |
/** |
| 11 |
* Exact, enumerated property names this converter owns. |
| 12 |
* |
| 13 |
* @return string[] |
| 14 |
*/ |
| 15 |
abstract protected function get_supported_properties(): array; |
| 16 |
|
| 17 |
public function is_supported( array $rule ): bool { |
| 18 |
$property = $rule['property'] ?? null; |
| 19 |
|
| 20 |
if ( ! is_string( $property ) || '' === $property ) { |
| 21 |
return false; |
| 22 |
} |
| 23 |
|
| 24 |
return in_array( $property, $this->get_supported_properties(), true ); |
| 25 |
} |
| 26 |
|
| 27 |
public function convert( Conversion_Context $context, array $rule ): bool { |
| 28 |
$custom = $this->get_custom_converter( $context, $rule ); |
| 29 |
|
| 30 |
if ( null !== $custom ) { |
| 31 |
return $custom(); |
| 32 |
} |
| 33 |
|
| 34 |
if ( null === $rule['value'] ) { |
| 35 |
return $this->convert_null( $context, $rule ); |
| 36 |
} |
| 37 |
|
| 38 |
return $this->do_convert( $context, $rule ); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Override to handle special-case rules before the standard null-check and do_convert path. |
| 43 |
* Receives the full rule (value may be null). Return null to fall through to default behavior. |
| 44 |
*/ |
| 45 |
protected function get_custom_converter( Conversion_Context $context, array $rule ): ?callable { |
| 46 |
return null; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Override to customize null-reset behavior. Default: set the prop to null directly. |
| 51 |
*/ |
| 52 |
protected function convert_null( Conversion_Context $context, array $rule ): bool { |
| 53 |
$context->set_prop( $rule['property'], null ); |
| 54 |
|
| 55 |
return true; |
| 56 |
} |
| 57 |
|
| 58 |
abstract protected function do_convert( Conversion_Context $context, array $rule ): bool; |
| 59 |
} |
| 60 |
|