PluginProbe
Elementor Website Builder – more than just a page builder / 3.32.0
Elementor Website Builder – more than just a page builder v3.32.0
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / modules / atomic-widgets / props-resolver / render-props-resolver.php

render-props-resolver.php in Elementor Website Builder – more than just a page builder 3.32.0, at modules/atomic-widgets/props-resolver/render-props-resolver.php

82 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\AtomicWidgets\PropsResolver;
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\Contracts\Prop_Type;
8 use Elementor\Modules\AtomicWidgets\PropTypes\Union_Prop_Type;
9 use Exception;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly.
13 }
14
15 class Render_Props_Resolver extends Props_Resolver {
16 /**
17 * Each transformer can return a value that is also a transformable value,
18 * which means that it can be transformed again by another transformer.
19 * This constant defines the maximum depth of transformations to avoid infinite loops.
20 */
21 const TRANSFORM_DEPTH_LIMIT = 3;
22
23 const CONTEXT_SETTINGS = 'settings';
24 const CONTEXT_STYLES = 'styles';
25
26 public static function for_styles(): self {
27 return static::instance( self::CONTEXT_STYLES );
28 }
29
30 public static function for_settings(): self {
31 return static::instance( self::CONTEXT_SETTINGS );
32 }
33
34 public function resolve( array $schema, array $props ): array {
35 $resolved = [];
36
37 foreach ( $schema as $key => $prop_type ) {
38 if ( ! ( $prop_type instanceof Prop_Type ) ) {
39 continue;
40 }
41
42 $transformed = $this->resolve_item(
43 $props[ $key ] ?? $prop_type->get_default(),
44 $key,
45 $prop_type
46 );
47
48 if ( Multi_Props::is( $transformed ) ) {
49 $resolved = array_merge( $resolved, Multi_Props::get_value( $transformed ) );
50
51 continue;
52 }
53
54 $resolved[ $key ] = $transformed;
55 }
56
57 return $resolved;
58 }
59
60 protected function resolve_item( $value, $key, Prop_Type $prop_type, int $depth = 0 ) {
61 if ( null === $value ) {
62 return null;
63 }
64
65 if ( ! $this->is_transformable( $value ) ) {
66 return $value;
67 }
68
69 if ( $depth >= self::TRANSFORM_DEPTH_LIMIT ) {
70 return null;
71 }
72
73 if ( isset( $value['disabled'] ) && true === $value['disabled'] ) {
74 return null;
75 }
76
77 $transformed = $this->transform( $value, $key, $prop_type );
78
79 return $this->resolve_item( $transformed, $key, $prop_type, $depth + 1 );
80 }
81 }
82