|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Vite plugin for Craft CMS |
|
4
|
|
|
* |
|
5
|
|
|
* Allows the use of the Vite.js next generation frontend tooling with Craft CMS |
|
6
|
|
|
* |
|
7
|
|
|
* @link https://nystudio107.com |
|
|
|
|
|
|
8
|
|
|
* @copyright Copyright (c) 2022 nystudio107 |
|
|
|
|
|
|
9
|
|
|
*/ |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace nystudio107\vite\services; |
|
12
|
|
|
|
|
13
|
|
|
use craft\helpers\ArrayHelper; |
|
14
|
|
|
use nystudio107\pluginvite\services\ViteService; |
|
15
|
|
|
use nystudio107\vite\helpers\PluginConfig as PluginConfigHelper; |
|
16
|
|
|
use nystudio107\vite\services\Helper as HelperService; |
|
17
|
|
|
use yii\base\InvalidConfigException; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
|
|
|
|
|
20
|
|
|
* @author nystudio107 |
|
|
|
|
|
|
21
|
|
|
* @package Vite |
|
|
|
|
|
|
22
|
|
|
* @since 1.0.29 |
|
|
|
|
|
|
23
|
|
|
* |
|
24
|
|
|
* @property ViteService $vite |
|
|
|
|
|
|
25
|
|
|
* @property HelperService $helper |
|
|
|
|
|
|
26
|
|
|
*/ |
|
|
|
|
|
|
27
|
|
|
trait ServicesTrait |
|
28
|
|
|
{ |
|
29
|
|
|
// Public Methods |
|
30
|
|
|
// ========================================================================= |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
|
|
|
|
|
33
|
|
|
* @inheritdoc |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct($id, $parent = null, array $config = []) |
|
36
|
|
|
{ |
|
37
|
|
|
// Merge in the passed config, so it our config can be overridden by Plugins::pluginConfigs['vite'] |
|
38
|
|
|
// ref: https://github.com/craftcms/cms/issues/1989 |
|
39
|
|
|
$config = ArrayHelper::merge([ |
|
|
|
|
|
|
40
|
|
|
'components' => [ |
|
41
|
|
|
'helper' => HelperService::class, |
|
42
|
|
|
'vite' => PluginConfigHelper::serviceDefinitionFromConfig('vite', ViteService::class) |
|
43
|
|
|
] |
|
44
|
|
|
], $config); |
|
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
parent::__construct($id, $parent, $config); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Returns the helper service |
|
51
|
|
|
* |
|
52
|
|
|
* @return HelperService The helper service |
|
53
|
|
|
* @throws InvalidConfigException |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getHelper(): HelperService |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->get('helper'); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Returns the vite service |
|
62
|
|
|
* |
|
63
|
|
|
* @return ViteService The helper service |
|
64
|
|
|
* @throws InvalidConfigException |
|
65
|
|
|
*/ |
|
66
|
|
|
public function getVite(): ViteService |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->get('vite'); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|