PluginProbe ʕ •ᴥ•ʔ
Hostinger Reach – AI-Powered Email Marketing for WordPress / 1.7.1
Hostinger Reach – AI-Powered Email Marketing for WordPress v1.7.1
1.7.2 1.7.1 1.7.0 1.6.0 1.5.9 1.5.8 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 trunk 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6
hostinger-reach / vendor / hostinger / hostinger-wp-amplitude / src / AmplitudeLoader.php
hostinger-reach / vendor / hostinger / hostinger-wp-amplitude / src Last commit date
ActionDispatcher.php 1 month ago AmplitudeLoader.php 1 month ago AmplitudeManager.php 1 month ago Rest.php 1 month ago
AmplitudeLoader.php
108 lines
1 <?php
2
3 namespace Hostinger\Amplitude;
4
5 use Hostinger\WpHelper\Config;
6 use Hostinger\WpHelper\Constants;
7 use Hostinger\WpHelper\Requests\Client;
8 use Hostinger\WpHelper\Utils as Helper;
9
10 class AmplitudeLoader
11 {
12 /**
13 * @var AmplitudeLoader instance.
14 */
15 private static ?AmplitudeLoader $instance = null;
16
17 /**
18 * @var array
19 */
20 private array $objects = [];
21
22 /**
23 * Allow only one instance of class
24 *
25 * @return self
26 */
27 public static function getInstance(): self
28 {
29 if (null === self::$instance) {
30 self::$instance = new self();
31 }
32
33 return self::$instance;
34 }
35
36 /**
37 * @return void
38 */
39 public function boot(): bool
40 {
41 $this->registerModules();
42
43 return true;
44 }
45
46 /**
47 * @return void
48 */
49 public function registerModules(): void
50 {
51 // Action Dispatcher.
52 $helper = new Helper();
53 $config = new Config();
54 $client = new Client(
55 $config->getConfigValue('base_rest_uri', Constants::HOSTINGER_REST_URI),
56 [
57 Config::TOKEN_HEADER => $helper->getApiToken(),
58 Config::DOMAIN_HEADER => $helper->getHostInfo(),
59 ]
60 );
61
62 $this->objects['action_dispatcher'] = new ActionDispatcher($helper, $config, $client);
63
64 // Amplitude Manager.
65 $this->objects['amplitude_rest'] = new Rest();
66 $this->objects['amplitude_rest']->init();
67
68 $this->addContainer();
69 }
70
71 /**
72 * @return bool
73 */
74 public function addContainer(): bool
75 {
76 if (empty($this->objects)) {
77 return false;
78 }
79
80 foreach ($this->objects as $object) {
81 if (property_exists($object, 'amplitude')) {
82 $object->setAmplitude($this);
83 }
84 }
85
86 return true;
87 }
88
89 /**
90 * @return string
91 */
92 public function getPluginInfo(): string
93 {
94 $plugin_url = '';
95
96 $plugins = get_plugins();
97 foreach ($plugins as $plugin_path => $plugin_info) {
98 if (str_contains(__FILE__, 'plugins/' . dirname($plugin_path) . '/')) {
99 $plugin_dir = dirname($plugin_path);
100
101 return plugins_url($plugin_dir);
102 }
103 }
104
105 return $plugin_url;
106 }
107 }
108