|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Instant Analytics plugin for Craft CMS |
|
4
|
|
|
* |
|
5
|
|
|
* Instant Analytics brings full Google Analytics support to your Twig templates |
|
6
|
|
|
* |
|
7
|
|
|
* @link https://nystudio107.com |
|
|
|
|
|
|
8
|
|
|
* @copyright Copyright (c) 2022 nystudio107 |
|
|
|
|
|
|
9
|
|
|
*/ |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace nystudio107\instantanalytics\services; |
|
12
|
|
|
|
|
13
|
|
|
use craft\helpers\ArrayHelper; |
|
14
|
|
|
use nystudio107\instantanalytics\assetbundles\instantanalytics\InstantAnalyticsAsset; |
|
15
|
|
|
use nystudio107\instantanalytics\services\Commerce as CommerceService; |
|
16
|
|
|
use nystudio107\instantanalytics\services\IA as IAService; |
|
17
|
|
|
use nystudio107\pluginvite\services\VitePluginService; |
|
18
|
|
|
use yii\base\InvalidConfigException; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
|
|
|
|
|
21
|
|
|
* @author nystudio107 |
|
|
|
|
|
|
22
|
|
|
* @package InstantAnalytics |
|
|
|
|
|
|
23
|
|
|
* @since 1.1.16 |
|
|
|
|
|
|
24
|
|
|
* |
|
25
|
|
|
* @property IAService $ia |
|
26
|
|
|
* @property CommerceService $commerce |
|
27
|
|
|
* @property VitePluginService $vite |
|
28
|
|
|
*/ |
|
|
|
|
|
|
29
|
|
|
trait ServicesTrait |
|
30
|
|
|
{ |
|
31
|
|
|
// Public Methods |
|
32
|
|
|
// ========================================================================= |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
|
|
|
|
|
35
|
|
|
* @inheritdoc |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct($id, $parent = null, array $config = []) |
|
38
|
|
|
{ |
|
39
|
|
|
// Merge in the passed config, so it our config can be overridden by Plugins::pluginConfigs['vite'] |
|
40
|
|
|
// ref: https://github.com/craftcms/cms/issues/1989 |
|
41
|
|
|
$config = ArrayHelper::merge([ |
|
|
|
|
|
|
42
|
|
|
'components' => [ |
|
43
|
|
|
'ia' => IAService::class, |
|
44
|
|
|
'commerce' => CommerceService::class, |
|
45
|
|
|
// Register the vite service |
|
46
|
|
|
'vite' => [ |
|
47
|
|
|
'class' => VitePluginService::class, |
|
48
|
|
|
'assetClass' => InstantAnalyticsAsset::class, |
|
49
|
|
|
'useDevServer' => true, |
|
50
|
|
|
'devServerPublic' => 'http://localhost:3001', |
|
51
|
|
|
'serverPublic' => 'http://localhost:8000', |
|
52
|
|
|
'errorEntry' => 'src/js/app.ts', |
|
53
|
|
|
'devServerInternal' => 'http://craft-instantanalytics-buildchain:3001', |
|
54
|
|
|
'checkDevServer' => true, |
|
55
|
|
|
], |
|
56
|
|
|
] |
|
57
|
|
|
], $config); |
|
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
parent::__construct($id, $parent, $config); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Returns the ia service |
|
64
|
|
|
* |
|
65
|
|
|
* @return IAService The ia service |
|
66
|
|
|
* @throws InvalidConfigException |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getIa(): IAService |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->get('ia'); |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Returns the commerce service |
|
75
|
|
|
* |
|
76
|
|
|
* @return CommerceService The commerce service |
|
77
|
|
|
* @throws InvalidConfigException |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getCommerce(): CommerceService |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->get('commerce'); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Returns the vite service |
|
86
|
|
|
* |
|
87
|
|
|
* @return VitePluginService The vite service |
|
88
|
|
|
* @throws InvalidConfigException |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getCoupons(): VitePluginService |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->get('vite'); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|