| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\Interactions\Validators; |
| 4 |
|
| 5 |
use Elementor\Modules\Interactions\Validators\String_Value as StringValueValidator; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; // Exit if accessed directly. |
| 9 |
} |
| 10 |
|
| 11 |
class Breakpoints_Value { |
| 12 |
public static function is_valid( $breakpoints_prop_value ) { |
| 13 |
if ( ! is_array( $breakpoints_prop_value ) ) { |
| 14 |
return false; |
| 15 |
} |
| 16 |
|
| 17 |
if ( ! isset( $breakpoints_prop_value['$$type'] ) || 'interaction-breakpoints' !== $breakpoints_prop_value['$$type'] ) { |
| 18 |
return false; |
| 19 |
} |
| 20 |
|
| 21 |
if ( ! isset( $breakpoints_prop_value['value'] ) || ! is_array( $breakpoints_prop_value['value'] ) ) { |
| 22 |
return false; |
| 23 |
} |
| 24 |
|
| 25 |
return self::validate_value( $breakpoints_prop_value['value'] ); |
| 26 |
} |
| 27 |
|
| 28 |
private static function validate_value( $value ) { |
| 29 |
if ( ! is_array( $value ) ) { |
| 30 |
return false; |
| 31 |
} |
| 32 |
|
| 33 |
if ( ! isset( $value['excluded'] ) || ! is_array( $value['excluded'] ) ) { |
| 34 |
return false; |
| 35 |
} |
| 36 |
|
| 37 |
return self::validate_excluded( $value['excluded'] ); |
| 38 |
} |
| 39 |
|
| 40 |
private static function validate_excluded( $excluded ) { |
| 41 |
if ( ! is_array( $excluded ) ) { |
| 42 |
return false; |
| 43 |
} |
| 44 |
|
| 45 |
if ( ! isset( $excluded['$$type'] ) || 'excluded-breakpoints' !== $excluded['$$type'] ) { |
| 46 |
return false; |
| 47 |
} |
| 48 |
|
| 49 |
if ( ! isset( $excluded['value'] ) || ! is_array( $excluded['value'] ) ) { |
| 50 |
return false; |
| 51 |
} |
| 52 |
|
| 53 |
return self::validate_excluded_value( $excluded['value'] ); |
| 54 |
} |
| 55 |
|
| 56 |
private static function validate_excluded_value( $value ) { |
| 57 |
if ( ! is_array( $value ) ) { |
| 58 |
return false; |
| 59 |
} |
| 60 |
|
| 61 |
foreach ( $value as $breakpoint_value ) { |
| 62 |
if ( ! StringValueValidator::is_valid( $breakpoint_value ) ) { |
| 63 |
return false; |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
return true; |
| 68 |
} |
| 69 |
} |
| 70 |
|