| 1 |
<?php |
| 2 |
namespace Elementor\Modules\Home\Classes; |
| 3 |
|
| 4 |
use Elementor\Core\Isolation\Wordpress_Adapter; |
| 5 |
use Elementor\Core\Isolation\Plugin_Status_Adapter; |
| 6 |
use Elementor\Includes\EditorAssetsAPI; |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; // Exit if accessed directly. |
| 10 |
} |
| 11 |
|
| 12 |
class Transformations_Manager { |
| 13 |
|
| 14 |
private static $cached_data = []; |
| 15 |
|
| 16 |
private const TRANSFORMATIONS = [ |
| 17 |
'Create_New_Page_Url', |
| 18 |
'Create_Edit_Website_Url', |
| 19 |
'Filter_Get_Started_By_License', |
| 20 |
'Filter_Sidebar_Promotion_By_License', |
| 21 |
'Create_Site_Settings_Url', |
| 22 |
'Filter_Top_Section_By_License', |
| 23 |
]; |
| 24 |
|
| 25 |
protected array $home_screen_data; |
| 26 |
|
| 27 |
protected Wordpress_Adapter $wordpress_adapter; |
| 28 |
|
| 29 |
protected Plugin_Status_Adapter $plugin_status_adapter; |
| 30 |
|
| 31 |
protected array $transformation_classes = []; |
| 32 |
|
| 33 |
public function __construct( $home_screen_data ) { |
| 34 |
$this->home_screen_data = $home_screen_data; |
| 35 |
$this->wordpress_adapter = new Wordpress_Adapter(); |
| 36 |
$this->plugin_status_adapter = new Plugin_Status_Adapter( $this->wordpress_adapter ); |
| 37 |
$this->transformation_classes = $this->get_transformation_classes(); |
| 38 |
} |
| 39 |
|
| 40 |
public function run_transformations(): array { |
| 41 |
if ( ! EditorAssetsAPI::is_valid_data( $this->home_screen_data ) ) { |
| 42 |
return []; |
| 43 |
} |
| 44 |
|
| 45 |
if ( ! empty( self::$cached_data ) ) { |
| 46 |
return self::$cached_data; |
| 47 |
} |
| 48 |
|
| 49 |
$transformations = self::TRANSFORMATIONS; |
| 50 |
|
| 51 |
foreach ( $transformations as $transformation_id ) { |
| 52 |
$this->home_screen_data = $this->transformation_classes[ $transformation_id ]->transform( $this->home_screen_data ); |
| 53 |
} |
| 54 |
|
| 55 |
self::$cached_data = $this->home_screen_data; |
| 56 |
|
| 57 |
return $this->home_screen_data; |
| 58 |
} |
| 59 |
|
| 60 |
private function get_transformation_classes(): array { |
| 61 |
$classes = []; |
| 62 |
|
| 63 |
$transformations = self::TRANSFORMATIONS; |
| 64 |
|
| 65 |
$arguments = [ |
| 66 |
'wordpress_adapter' => $this->wordpress_adapter, |
| 67 |
'plugin_status_adapter' => $this->plugin_status_adapter, |
| 68 |
]; |
| 69 |
|
| 70 |
foreach ( $transformations as $transformation_id ) { |
| 71 |
$class_name = '\\Elementor\\Modules\\Home\\Transformations\\' . $transformation_id; |
| 72 |
$classes[ $transformation_id ] = new $class_name( $arguments ); |
| 73 |
} |
| 74 |
|
| 75 |
return $classes; |
| 76 |
} |
| 77 |
} |
| 78 |
|