| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\Variables\Classes; |
| 4 |
|
| 5 |
use Elementor\Modules\AtomicWidgets\PropTypes\Base\Array_Prop_Type; |
| 6 |
use Elementor\Modules\AtomicWidgets\PropTypes\Base\Object_Prop_Type; |
| 7 |
use Elementor\Modules\AtomicWidgets\PropTypes\Color_Prop_Type; |
| 8 |
use Elementor\Modules\AtomicWidgets\PropTypes\Union_Prop_Type; |
| 9 |
use Elementor\Modules\Variables\PropTypes\Color_Variable as Color_Variable_Prop_Type; |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit; // Exit if accessed directly. |
| 13 |
} |
| 14 |
|
| 15 |
class Style_Schema { |
| 16 |
public function augment( array $schema ): array { |
| 17 |
$result = []; |
| 18 |
|
| 19 |
foreach ( $schema as $key => $prop_type ) { |
| 20 |
$result[ $key ] = $this->update( $prop_type ); |
| 21 |
} |
| 22 |
|
| 23 |
return $result; |
| 24 |
} |
| 25 |
|
| 26 |
private function update( $prop_type ) { |
| 27 |
if ( $prop_type instanceof Color_Prop_Type ) { |
| 28 |
return $this->update_color( $prop_type ); |
| 29 |
} |
| 30 |
|
| 31 |
if ( $prop_type instanceof Union_Prop_Type ) { |
| 32 |
return $this->update_union( $prop_type ); |
| 33 |
} |
| 34 |
|
| 35 |
if ( $prop_type instanceof Object_Prop_Type ) { |
| 36 |
return $this->update_object( $prop_type ); |
| 37 |
} |
| 38 |
|
| 39 |
if ( $prop_type instanceof Array_Prop_Type ) { |
| 40 |
return $this->update_array( $prop_type ); |
| 41 |
} |
| 42 |
|
| 43 |
return $prop_type; |
| 44 |
} |
| 45 |
|
| 46 |
private function update_color( Color_Prop_Type $color_prop_type ) { |
| 47 |
return Union_Prop_Type::create_from( $color_prop_type ) |
| 48 |
->add_prop_type( Color_Variable_Prop_Type::make() ); |
| 49 |
} |
| 50 |
|
| 51 |
private function update_array( Array_Prop_Type $array_prop_type ) { |
| 52 |
return $array_prop_type->set_item_type( |
| 53 |
$this->update( $array_prop_type->get_item_type() ) |
| 54 |
); |
| 55 |
} |
| 56 |
|
| 57 |
private function update_object( Object_Prop_Type $object_prop_type ) { |
| 58 |
return $object_prop_type->set_shape( |
| 59 |
$this->augment( $object_prop_type->get_shape() ) |
| 60 |
); |
| 61 |
} |
| 62 |
|
| 63 |
private function update_union( Union_Prop_Type $union_prop_type ) { |
| 64 |
$new_union = Union_Prop_Type::make(); |
| 65 |
|
| 66 |
foreach ( $union_prop_type->get_prop_types() as $prop_type ) { |
| 67 |
$updated = $this->update( $prop_type ); |
| 68 |
|
| 69 |
if ( $updated instanceof Union_Prop_Type ) { |
| 70 |
foreach ( $updated->get_prop_types() as $prop_type ) { |
| 71 |
$new_union->add_prop_type( $prop_type ); |
| 72 |
} |
| 73 |
|
| 74 |
continue; |
| 75 |
} |
| 76 |
|
| 77 |
$new_union->add_prop_type( $updated ); |
| 78 |
} |
| 79 |
|
| 80 |
return $new_union; |
| 81 |
} |
| 82 |
} |
| 83 |
|