|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* SEOmatic plugin for Craft CMS |
|
4
|
|
|
* |
|
5
|
|
|
* A turnkey SEO implementation for Craft CMS that is comprehensive, powerful, |
|
6
|
|
|
* and flexible |
|
7
|
|
|
* |
|
8
|
|
|
* @link https://nystudio107.com |
|
9
|
|
|
* @copyright Copyright (c) 2022 nystudio107 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace nystudio107\seomatic\services; |
|
13
|
|
|
|
|
14
|
|
|
use craft\helpers\ArrayHelper; |
|
15
|
|
|
use nystudio107\pluginvite\services\VitePluginService; |
|
16
|
|
|
use nystudio107\seomatic\assetbundles\seomatic\SeomaticAsset; |
|
17
|
|
|
use nystudio107\seomatic\services\FrontendTemplates as FrontendTemplatesService; |
|
18
|
|
|
use nystudio107\seomatic\services\Helper as HelperService; |
|
19
|
|
|
use nystudio107\seomatic\services\JsonLd as JsonLdService; |
|
20
|
|
|
use nystudio107\seomatic\services\Link as LinkService; |
|
21
|
|
|
use nystudio107\seomatic\services\MetaBundles as MetaBundlesService; |
|
22
|
|
|
use nystudio107\seomatic\services\MetaContainers as MetaContainersService; |
|
23
|
|
|
use nystudio107\seomatic\services\Script as ScriptService; |
|
24
|
|
|
use nystudio107\seomatic\services\SeoElements as SeoElementsService; |
|
25
|
|
|
use nystudio107\seomatic\services\Sitemaps as SitemapsService; |
|
26
|
|
|
use nystudio107\seomatic\services\Tag as TagService; |
|
27
|
|
|
use nystudio107\seomatic\services\Title as TitleService; |
|
28
|
|
|
use yii\base\InvalidConfigException; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @author nystudio107 |
|
32
|
|
|
* @package Seomatic |
|
33
|
|
|
* @since 3.4.38 |
|
34
|
|
|
* |
|
35
|
|
|
* @property FrontendTemplatesService $frontendTemplates |
|
36
|
|
|
* @property HelperService $helper |
|
37
|
|
|
* @property JsonLdService $jsonLd |
|
38
|
|
|
* @property LinkService $link |
|
39
|
|
|
* @property MetaBundlesService $metaBundles |
|
40
|
|
|
* @property MetaContainersService $metaContainers |
|
41
|
|
|
* @property ScriptService $script |
|
42
|
|
|
* @property SeoElementsService $seoElements |
|
43
|
|
|
* @property SitemapsService $sitemaps |
|
44
|
|
|
* @property TagService $tag |
|
45
|
|
|
* @property TitleService $title |
|
46
|
|
|
* @property VitePluginService $vite |
|
47
|
|
|
*/ |
|
48
|
|
|
trait ServicesTrait |
|
49
|
|
|
{ |
|
50
|
|
|
// Public Methods |
|
51
|
|
|
// ========================================================================= |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @inheritdoc |
|
55
|
|
|
*/ |
|
56
|
|
|
public function __construct($id, $parent = null, array $config = []) |
|
57
|
|
|
{ |
|
58
|
|
|
// Merge in the passed config, so it our config can be overridden by Plugins::pluginConfigs['vite'] |
|
59
|
|
|
// ref: https://github.com/craftcms/cms/issues/1989 |
|
60
|
|
|
$config = ArrayHelper::merge([ |
|
61
|
|
|
'components' => [ |
|
62
|
|
|
'frontendTemplates' => FrontendTemplatesService::class, |
|
63
|
|
|
'helper' => HelperService::class, |
|
64
|
|
|
'jsonLd' => JsonLdService::class, |
|
65
|
|
|
'link' => LinkService::class, |
|
66
|
|
|
'metaBundles' => MetaBundlesService::class, |
|
67
|
|
|
'metaContainers' => MetaContainersService::class, |
|
68
|
|
|
'script' => ScriptService::class, |
|
69
|
|
|
'seoElements' => SeoElementsService::class, |
|
70
|
|
|
'sitemaps' => SitemapsService::class, |
|
71
|
|
|
'tag' => TagService::class, |
|
72
|
|
|
'title' => TitleService::class, |
|
73
|
|
|
// Register the vite service |
|
74
|
|
|
'vite' => [ |
|
75
|
|
|
'class' => VitePluginService::class, |
|
76
|
|
|
'assetClass' => SeomaticAsset::class, |
|
77
|
|
|
'useDevServer' => true, |
|
78
|
|
|
'devServerPublic' => 'http://localhost:3001', |
|
79
|
|
|
'serverPublic' => 'http://localhost:8000', |
|
80
|
|
|
'errorEntry' => 'src/js/seomatic.js', |
|
81
|
|
|
'devServerInternal' => 'http://craft-seomatic-buildchain:3001', |
|
82
|
|
|
'checkDevServer' => true, |
|
83
|
|
|
], |
|
84
|
|
|
] |
|
85
|
|
|
], $config); |
|
86
|
|
|
|
|
87
|
|
|
parent::__construct($id, $parent, $config); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Returns the frontendTemplates service |
|
92
|
|
|
* |
|
93
|
|
|
* @return FrontendTemplatesService The frontendTemplates service |
|
94
|
|
|
* @throws InvalidConfigException |
|
95
|
|
|
*/ |
|
96
|
|
|
public function getFrontendTemplates(): FrontendTemplatesService |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->get('frontendTemplates'); |
|
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Returns the helper service |
|
103
|
|
|
* |
|
104
|
|
|
* @return HelperService The helper service |
|
105
|
|
|
* @throws InvalidConfigException |
|
106
|
|
|
*/ |
|
107
|
|
|
public function getHelper(): HelperService |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->get('helper'); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Returns the jsonLd service |
|
114
|
|
|
* |
|
115
|
|
|
* @return JsonLdService The jsonLd service |
|
116
|
|
|
* @throws InvalidConfigException |
|
117
|
|
|
*/ |
|
118
|
|
|
public function getJsonLd(): JsonLdService |
|
119
|
|
|
{ |
|
120
|
|
|
return $this->get('jsonLd'); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Returns the link service |
|
125
|
|
|
* |
|
126
|
|
|
* @return LinkService The link service |
|
127
|
|
|
* @throws InvalidConfigException |
|
128
|
|
|
*/ |
|
129
|
|
|
public function getLink(): LinkService |
|
130
|
|
|
{ |
|
131
|
|
|
return $this->get('link'); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Returns the metaBundles service |
|
136
|
|
|
* |
|
137
|
|
|
* @return MetaBundlesService The metaBundles service |
|
138
|
|
|
* @throws InvalidConfigException |
|
139
|
|
|
*/ |
|
140
|
|
|
public function getMetaBundles(): MetaBundlesService |
|
141
|
|
|
{ |
|
142
|
|
|
return $this->get('metaBundles'); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Returns the metaContainers service |
|
147
|
|
|
* |
|
148
|
|
|
* @return MetaContainersService The metaContainers service |
|
149
|
|
|
* @throws InvalidConfigException |
|
150
|
|
|
*/ |
|
151
|
|
|
public function getMetaContainers(): MetaContainersService |
|
152
|
|
|
{ |
|
153
|
|
|
return $this->get('metaContainers'); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Returns the script service |
|
158
|
|
|
* |
|
159
|
|
|
* @return ScriptService The script service |
|
160
|
|
|
* @throws InvalidConfigException |
|
161
|
|
|
*/ |
|
162
|
|
|
public function getScript(): ScriptService |
|
163
|
|
|
{ |
|
164
|
|
|
return $this->get('script'); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Returns the seoElements service |
|
169
|
|
|
* |
|
170
|
|
|
* @return SeoElementsService The seoElements service |
|
171
|
|
|
* @throws InvalidConfigException |
|
172
|
|
|
*/ |
|
173
|
|
|
public function getSeoElements(): SeoElementsService |
|
174
|
|
|
{ |
|
175
|
|
|
return $this->get('seoElements'); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* Returns the sitemaps service |
|
180
|
|
|
* |
|
181
|
|
|
* @return SitemapsService The sitemaps service |
|
182
|
|
|
* @throws InvalidConfigException |
|
183
|
|
|
*/ |
|
184
|
|
|
public function getSitemaps(): SitemapsService |
|
185
|
|
|
{ |
|
186
|
|
|
return $this->get('sitemaps'); |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* Returns the tag service |
|
191
|
|
|
* |
|
192
|
|
|
* @return TagService The tag service |
|
193
|
|
|
* @throws InvalidConfigException |
|
194
|
|
|
*/ |
|
195
|
|
|
public function getTag(): TagService |
|
196
|
|
|
{ |
|
197
|
|
|
return $this->get('tag'); |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* Returns the title service |
|
202
|
|
|
* |
|
203
|
|
|
* @return TitleService The title service |
|
204
|
|
|
* @throws InvalidConfigException |
|
205
|
|
|
*/ |
|
206
|
|
|
public function getTitle(): TitleService |
|
207
|
|
|
{ |
|
208
|
|
|
return $this->get('title'); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* Returns the vite service |
|
213
|
|
|
* |
|
214
|
|
|
* @return VitePluginService The vite service |
|
215
|
|
|
* @throws InvalidConfigException |
|
216
|
|
|
*/ |
|
217
|
|
|
public function getVite(): VitePluginService |
|
218
|
|
|
{ |
|
219
|
|
|
return $this->get('vite'); |
|
220
|
|
|
} |
|
221
|
|
|
} |
|
222
|
|
|
|