| 1 |
<?php |
| 2 |
namespace Elementor\Modules\Components\Utils; |
| 3 |
|
| 4 |
use Elementor\Plugin; |
| 5 |
use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Element_Base; |
| 6 |
use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Widget_Base; |
| 7 |
use Elementor\Modules\AtomicWidgets\Utils\Utils; |
| 8 |
use Elementor\Modules\AtomicWidgets\PropTypes\Contracts\Prop_Type; |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
exit; // Exit if accessed directly. |
| 12 |
} |
| 13 |
|
| 14 |
class Parsing_Utils { |
| 15 |
public static function get_prop_type( string $el_type, string $widget_type, string $prop_key ): Prop_Type { |
| 16 |
$element = Plugin::$instance->elements_manager->get_element( $el_type, $widget_type ); |
| 17 |
|
| 18 |
if ( ! $element ) { |
| 19 |
throw new \Exception( esc_html( "Invalid element: Element type $el_type with widget type $widget_type is not registered." ) ); |
| 20 |
} |
| 21 |
|
| 22 |
$element_instance = new $element(); |
| 23 |
|
| 24 |
/** @var Atomic_Element_Base | Atomic_Widget_Base $element_instance */ |
| 25 |
if ( ! Utils::is_atomic( $element_instance ) ) { |
| 26 |
throw new \Exception( esc_html( "Invalid element: Element type $el_type with widget type $widget_type is not an atomic element/widget." ) ); |
| 27 |
} |
| 28 |
|
| 29 |
$props_schema = $element_instance->get_props_schema(); |
| 30 |
|
| 31 |
if ( ! isset( $props_schema[ $prop_key ] ) ) { |
| 32 |
throw new \Exception( esc_html( "Prop key '$prop_key' does not exist in the schema of element '{$element_instance->get_element_type()}'." ) ); |
| 33 |
} |
| 34 |
|
| 35 |
return $props_schema[ $prop_key ]; |
| 36 |
} |
| 37 |
|
| 38 |
public static function get_duplicates( array $array ): array { |
| 39 |
$duplicates = []; |
| 40 |
$seen = []; |
| 41 |
|
| 42 |
foreach ( $array as $item ) { |
| 43 |
if ( in_array( $item, $seen, true ) ) { |
| 44 |
if ( ! in_array( $item, $duplicates, true ) ) { |
| 45 |
$duplicates[] = $item; |
| 46 |
} |
| 47 |
} else { |
| 48 |
$seen[] = $item; |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
return $duplicates; |
| 53 |
} |
| 54 |
} |
| 55 |
|