| 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 Shorthand_Expander_Base implements Shorthand_Expander { |
| 10 |
/** |
| 11 |
* Exact, enumerated shorthand property names this expander 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 expand( array $rule ): array { |
| 28 |
if ( null === $rule['value'] ) { |
| 29 |
return $this->expand_null( $rule ); |
| 30 |
} |
| 31 |
|
| 32 |
return $this->do_expand( $rule ); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Override to fan out null resets to all longhand properties. |
| 37 |
* Default: re-emit the same property with a null value (covers simple renamers). |
| 38 |
* |
| 39 |
* @return array<int, array{property: string, value: null, declaration: string}> |
| 40 |
*/ |
| 41 |
protected function expand_null( array $rule ): array { |
| 42 |
return [ $this->null_rule( $rule['property'] ) ]; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* @return array{property: string, value: null, declaration: string} |
| 47 |
*/ |
| 48 |
protected function null_rule( string $property ): array { |
| 49 |
return [ |
| 50 |
'property' => $property, |
| 51 |
'value' => null, |
| 52 |
'declaration' => $property . ': ', |
| 53 |
]; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* @param array{property: string, value: string} $rule A rule with a guaranteed non-null value. |
| 58 |
* @return array<int, array{property: string, value: string, declaration: string}> |
| 59 |
*/ |
| 60 |
abstract protected function do_expand( array $rule ): array; |
| 61 |
} |
| 62 |
|