| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\AtomicWidgets\PropsResolver; |
| 4 |
|
| 5 |
use Elementor\Modules\AtomicWidgets\PropTypes\Contracts\Prop_Type; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; // Exit if accessed directly. |
| 9 |
} |
| 10 |
|
| 11 |
class Import_Export_Props_Resolver extends Props_Resolver { |
| 12 |
const CONTEXT_IMPORT = 'import'; |
| 13 |
const CONTEXT_EXPORT = 'export'; |
| 14 |
|
| 15 |
public static function for_import() { |
| 16 |
return static::instance( self::CONTEXT_IMPORT ); |
| 17 |
} |
| 18 |
|
| 19 |
public static function for_export() { |
| 20 |
return static::instance( self::CONTEXT_EXPORT ); |
| 21 |
} |
| 22 |
|
| 23 |
public function resolve( array $schema, array $props ): array { |
| 24 |
$resolved = []; |
| 25 |
|
| 26 |
foreach ( $schema as $key => $prop_type ) { |
| 27 |
if ( ! ( $prop_type instanceof Prop_Type ) ) { |
| 28 |
continue; |
| 29 |
} |
| 30 |
|
| 31 |
$value = $this->resolve_item( $props[ $key ] ?? null, $key, $prop_type ); |
| 32 |
|
| 33 |
if ( null === $value ) { |
| 34 |
continue; |
| 35 |
} |
| 36 |
|
| 37 |
$resolved[ $key ] = $value; |
| 38 |
} |
| 39 |
|
| 40 |
return $resolved; |
| 41 |
} |
| 42 |
|
| 43 |
protected function resolve_item( $value, $key, Prop_Type $prop_type ) { |
| 44 |
if ( null === $value ) { |
| 45 |
return null; |
| 46 |
} |
| 47 |
|
| 48 |
if ( ! $this->is_transformable( $value ) ) { |
| 49 |
return $value; |
| 50 |
} |
| 51 |
|
| 52 |
return $this->transform( $value, $key, $prop_type ); |
| 53 |
} |
| 54 |
} |
| 55 |
|