1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Transcoder plugin for Craft CMS |
4
|
|
|
* |
5
|
|
|
* Transcode videos to various formats, and provide thumbnails of the video |
6
|
|
|
* |
7
|
|
|
* @link https://nystudio107.com |
|
|
|
|
8
|
|
|
* @copyright Copyright (c) 2022 nystudio107 |
|
|
|
|
9
|
|
|
*/ |
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace nystudio107\transcoder\services; |
12
|
|
|
|
13
|
|
|
use nystudio107\pluginvite\services\VitePluginService; |
14
|
|
|
use nystudio107\transcoder\assetbundles\transcoder\TranscoderAsset; |
15
|
|
|
use yii\base\InvalidConfigException; |
16
|
|
|
|
17
|
|
|
/** |
|
|
|
|
18
|
|
|
* @author nystudio107 |
|
|
|
|
19
|
|
|
* @package Transcode |
|
|
|
|
20
|
|
|
* @since 1.2.23 |
|
|
|
|
21
|
|
|
* |
22
|
|
|
* @property Transcode $transcode |
23
|
|
|
* @property VitePluginService $vite |
24
|
|
|
*/ |
|
|
|
|
25
|
|
|
trait ServicesTrait |
26
|
|
|
{ |
27
|
|
|
// Public Static Methods |
28
|
|
|
// ========================================================================= |
29
|
|
|
|
30
|
|
|
/** |
|
|
|
|
31
|
|
|
* @inheritdoc |
32
|
|
|
*/ |
|
|
|
|
33
|
|
|
public static function config(): array |
34
|
|
|
{ |
35
|
|
|
// Constants aren't allowed in traits until PHP >= 8.2, and config() is called before __construct(), |
36
|
|
|
// so we can't extract it from the passed in $config |
37
|
|
|
$majorVersion = '5'; |
38
|
|
|
// Dev server container name & port are based on the major version of this plugin |
39
|
|
|
$devPort = 3000 + (int)$majorVersion; |
40
|
|
|
$versionName = 'v' . $majorVersion; |
41
|
|
|
return [ |
42
|
|
|
'components' => [ |
43
|
|
|
'transcode' => Transcode::class, |
44
|
|
|
// Register the vite service |
45
|
|
|
'vite' => [ |
46
|
|
|
'class' => VitePluginService::class, |
47
|
|
|
'assetClass' => TranscoderAsset::class, |
48
|
|
|
'useDevServer' => true, |
49
|
|
|
'devServerInternal' => 'http://craft-transcoder-' . $versionName . '-buildchain-dev:' . $devPort, |
50
|
|
|
'devServerPublic' => 'http://localhost:' . $devPort, |
51
|
|
|
'errorEntry' => 'src/js/app.ts', |
52
|
|
|
'checkDevServer' => true, |
53
|
|
|
], |
54
|
|
|
], |
55
|
|
|
]; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
// Public Methods |
59
|
|
|
// ========================================================================= |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Returns the transcode service |
63
|
|
|
* |
64
|
|
|
* @return Transcode The transcode service |
65
|
|
|
* @throws InvalidConfigException |
66
|
|
|
*/ |
67
|
|
|
public function getTranscode(): Transcode |
68
|
|
|
{ |
69
|
|
|
return $this->get('transcode'); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Returns the vite service |
74
|
|
|
* |
75
|
|
|
* @return VitePluginService The vite service |
76
|
|
|
* @throws InvalidConfigException |
77
|
|
|
*/ |
78
|
|
|
public function getVite(): VitePluginService |
79
|
|
|
{ |
80
|
|
|
return $this->get('vite'); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|