PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.4
Elementor Website Builder – more than just a page builder v4.3.4
4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.3.0-beta3 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 All 457 releases
elementor / modules / mcp / abilities / utils / dropped-plain-keys-finder.php

dropped-plain-keys-finder.php in Elementor Website Builder – more than just a page builder 4.3.4, at modules/mcp/abilities/utils/dropped-plain-keys-finder.php

60 lines 1.6 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\Mcp\Abilities\Utils;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 /**
10 * Finds keys of a plain input value that did not survive plain → envelope resolution,
11 * either because they are not fields of the prop or because their value could not be resolved.
12 * Compares against the resolver output instead of the schema so unions, custom resolvers
13 * and open slots are judged by what was actually stored.
14 */
15 class Dropped_Plain_Keys_Finder {
16
17 /**
18 * @return string[] Dotted paths relative to $path.
19 */
20 public static function find( $plain_value, $resolved_value, string $path ): array {
21 $plain_fields = self::unwrap( $plain_value );
22 $resolved_fields = self::unwrap( $resolved_value );
23
24 if ( ! self::is_object_map( $plain_fields ) || ! is_array( $resolved_fields ) || ! self::is_envelope( $resolved_value ) ) {
25 return [];
26 }
27
28 $dropped = [];
29
30 foreach ( $plain_fields as $key => $sub_value ) {
31 if ( null === $sub_value ) {
32 continue;
33 }
34
35 $sub_path = $path . '.' . $key;
36
37 if ( ! array_key_exists( $key, $resolved_fields ) ) {
38 $dropped[] = $sub_path;
39 continue;
40 }
41
42 $dropped = array_merge( $dropped, self::find( $sub_value, $resolved_fields[ $key ], $sub_path ) );
43 }
44
45 return $dropped;
46 }
47
48 private static function unwrap( $value ) {
49 return self::is_envelope( $value ) ? $value['value'] : $value;
50 }
51
52 private static function is_envelope( $value ): bool {
53 return is_array( $value ) && isset( $value['$$type'] ) && array_key_exists( 'value', $value );
54 }
55
56 private static function is_object_map( $value ): bool {
57 return is_array( $value ) && ! empty( $value ) && ! wp_is_numeric_array( $value );
58 }
59 }
60