| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\AtomicWidgets\CssConverter\Converters; |
| 4 |
|
| 5 |
use Elementor\Modules\AtomicWidgets\CssConverter\Conversion_Context; |
| 6 |
use Elementor\Modules\AtomicWidgets\CssConverter\Property_Converter_Base; |
| 7 |
use Elementor\Modules\AtomicWidgets\PropTypes\Primitives\Number_Prop_Type; |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; // Exit if accessed directly. |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Reusable converter for properties backed by a Number_Prop_Type. One instance per property. |
| 15 |
* Accepts only a strict numeric value (no units, no functions); anything else declines (-> custom_css). |
| 16 |
* Emits the canonical Number PropValue from generate(). |
| 17 |
*/ |
| 18 |
class Number_Property_Converter extends Property_Converter_Base { |
| 19 |
private string $property; |
| 20 |
|
| 21 |
public function __construct( string $property ) { |
| 22 |
$this->property = $property; |
| 23 |
} |
| 24 |
|
| 25 |
protected function get_supported_properties(): array { |
| 26 |
return [ $this->property ]; |
| 27 |
} |
| 28 |
|
| 29 |
protected function do_convert( Conversion_Context $context, array $rule ): bool { |
| 30 |
$value = trim( $rule['value'] ); |
| 31 |
|
| 32 |
if ( ! is_numeric( $value ) ) { |
| 33 |
return false; |
| 34 |
} |
| 35 |
|
| 36 |
$context->set_prop( $this->property, Number_Prop_Type::generate( $value + 0 ) ); |
| 37 |
|
| 38 |
return true; |
| 39 |
} |
| 40 |
} |
| 41 |
|