PluginProbe
Elementor Website Builder – more than just a page builder / 3.25.2
Elementor Website Builder – more than just a page builder v3.25.2
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 / settings-validator.php

settings-validator.php in Elementor Website Builder – more than just a page builder 3.25.2, at modules/atomic-widgets/settings-validator.php

63 lines 1.1 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;
4
5 use Elementor\Core\Utils\Collection;
6 use Elementor\Modules\AtomicWidgets\PropTypes\Prop_Type;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 class Settings_Validator {
13
14 private array $schema;
15
16 public function __construct( array $schema ) {
17 $this->schema = $schema;
18 }
19
20 public static function make( array $schema ): self {
21 return new static( $schema );
22 }
23
24 /**
25 * @param array $settings
26 *
27 * @return array{
28 * 0: bool,
29 * 1: array<string, mixed>,
30 * 2: array<string>
31 * }
32 */
33 public function validate( array $settings ): array {
34 $validated = [];
35 $errors = [];
36
37 foreach ( $settings as $key => $value ) {
38 $prop_type = $this->schema[ $key ] ?? null;
39
40 if ( ! ( $prop_type instanceof Prop_Type ) ) {
41 continue;
42 }
43
44 try {
45 $prop_type->validate_with_additional( $value );
46 } catch ( \Exception $e ) {
47 $errors[] = $key;
48 continue;
49 }
50
51 $validated[ $key ] = $value;
52 }
53
54 $is_valid = empty( $errors );
55
56 return [
57 $is_valid,
58 $validated,
59 $errors,
60 ];
61 }
62 }
63