|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Retour plugin for Craft CMS |
|
4
|
|
|
* |
|
5
|
|
|
* Retour allows you to intelligently redirect legacy URLs, so that you don't |
|
6
|
|
|
* lose SEO value when rebuilding & restructuring a website |
|
7
|
|
|
* |
|
8
|
|
|
* @link https://nystudio107.com/ |
|
|
|
|
|
|
9
|
|
|
* @copyright Copyright (c) 2018 nystudio107 |
|
|
|
|
|
|
10
|
|
|
*/ |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
namespace nystudio107\retour\services; |
|
13
|
|
|
|
|
14
|
|
|
use nystudio107\pluginvite\services\VitePluginService; |
|
15
|
|
|
use nystudio107\retour\assetbundles\retour\RetourAsset; |
|
16
|
|
|
use yii\base\InvalidConfigException; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
|
|
|
|
|
19
|
|
|
* @author nystudio107 |
|
|
|
|
|
|
20
|
|
|
* @package Retour |
|
|
|
|
|
|
21
|
|
|
* @since 4.1.4 |
|
|
|
|
|
|
22
|
|
|
* |
|
23
|
|
|
* @property Events $events |
|
24
|
|
|
* @property Redirects $redirects |
|
25
|
|
|
* @property Statistics $statistics |
|
26
|
|
|
* @property VitePluginService $vite |
|
27
|
|
|
*/ |
|
|
|
|
|
|
28
|
|
|
trait ServicesTrait |
|
29
|
|
|
{ |
|
30
|
|
|
// Public Static Methods |
|
31
|
|
|
// ========================================================================= |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
|
|
|
|
|
34
|
|
|
* @inheritdoc |
|
35
|
|
|
*/ |
|
|
|
|
|
|
36
|
|
|
public static function config(): array |
|
37
|
|
|
{ |
|
38
|
|
|
// Constants aren't allowed in traits until PHP >= 8.2, and config() is called before __construct(), |
|
39
|
|
|
// so we can't extract it from the passed in $config |
|
40
|
|
|
$majorVersion = '5'; |
|
41
|
|
|
// Dev server container name & port are based on the major version of this plugin |
|
42
|
|
|
$devPort = 3000 + (int)$majorVersion; |
|
43
|
|
|
$versionName = 'v' . $majorVersion; |
|
44
|
|
|
return [ |
|
45
|
|
|
'components' => [ |
|
46
|
|
|
'events' => Events::class, |
|
47
|
|
|
'redirects' => Redirects::class, |
|
48
|
|
|
'statistics' => Statistics::class, |
|
49
|
|
|
// Register the vite service |
|
50
|
|
|
'vite' => [ |
|
51
|
|
|
'assetClass' => RetourAsset::class, |
|
52
|
|
|
'checkDevServer' => true, |
|
53
|
|
|
'class' => VitePluginService::class, |
|
54
|
|
|
'devServerInternal' => 'http://craft-retour-' . $versionName . '-buildchain-dev:' . $devPort, |
|
55
|
|
|
'devServerPublic' => 'http://localhost:' . $devPort, |
|
56
|
|
|
'errorEntry' => 'src/js/Retour.js', |
|
57
|
|
|
'useDevServer' => true, |
|
58
|
|
|
], |
|
59
|
|
|
], |
|
60
|
|
|
]; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
// Public Methods |
|
64
|
|
|
// ========================================================================= |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Returns the events service |
|
68
|
|
|
* |
|
69
|
|
|
* @return Events The events service |
|
70
|
|
|
* @throws InvalidConfigException |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getEvents(): Events |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->get('events'); |
|
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Returns the redirects service |
|
79
|
|
|
* |
|
80
|
|
|
* @return Redirects The redirects service |
|
81
|
|
|
* @throws InvalidConfigException |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getRedirects(): Redirects |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->get('redirects'); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Returns the statistics service |
|
90
|
|
|
* |
|
91
|
|
|
* @return Statistics The statistics service |
|
92
|
|
|
* @throws InvalidConfigException |
|
93
|
|
|
*/ |
|
94
|
|
|
public function getStatistics(): Statistics |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->get('statistics'); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Returns the vite service |
|
101
|
|
|
* |
|
102
|
|
|
* @return VitePluginService The vite service |
|
103
|
|
|
* @throws InvalidConfigException |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getVite(): VitePluginService |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->get('vite'); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|