1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Assets; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* AssetBundle represents a collection of asset files, such as CSS, JS, images. |
9
|
|
|
* |
10
|
|
|
* Each asset bundle has a unique name that globally identifies it among all asset bundles used in an application. |
11
|
|
|
* The name is the fully qualified class name {@see https://www.php.net/manual/en/language.namespaces.rules.php} |
12
|
|
|
* of the class representing it. |
13
|
|
|
* |
14
|
|
|
* An asset bundle can depend on other asset bundles. When registering an asset bundle with a view, all its dependent |
15
|
|
|
* asset bundles will be automatically registered. |
16
|
|
|
*/ |
17
|
|
|
class AssetBundle |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var string|null The Web-accessible directory that contains the asset files in this bundle. |
21
|
|
|
* |
22
|
|
|
* If {@see $sourcePath} is set, this property will be *overwritten* by {@see AssetManager} when it publishes the |
23
|
|
|
* asset files from {@see $sourcePath}. |
24
|
|
|
* |
25
|
|
|
* You can use either a directory or an alias of the directory. |
26
|
|
|
*/ |
27
|
|
|
public ?string $basePath = null; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string|null The base URL for the relative asset files listed in {@see $js} and {@see $css}. |
31
|
|
|
* |
32
|
|
|
* If {@see $sourcePath} is set, this property will be *overwritten* by {@see AssetManager} when it publishes the |
33
|
|
|
* asset files from {@see $sourcePath}. |
34
|
|
|
* |
35
|
|
|
* You can use either a URL or an alias of the URL. |
36
|
|
|
*/ |
37
|
|
|
public ?string $baseUrl = null; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var bool Indicates whether the AssetBundle uses CDN exclusively. |
41
|
|
|
*/ |
42
|
|
|
public bool $cdn = false; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var array List of CSS files that this bundle contains. Each CSS file can be specified in one of the three |
46
|
|
|
* formats as explained in {@see $js}. |
47
|
|
|
* |
48
|
|
|
* Note that only a forward slash "/" should be used as directory separator. |
49
|
|
|
*/ |
50
|
|
|
public array $css = []; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var array The options that will be passed to {@see \Yiisoft\View\WebView::registerCssFile()} |
54
|
|
|
* when registering the CSS files in this bundle. |
55
|
|
|
*/ |
56
|
|
|
public array $cssOptions = []; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var array The options line command from converter. |
60
|
|
|
* |
61
|
|
|
* Example: Dart SASS minify css. |
62
|
|
|
* |
63
|
|
|
* public array $converterOptions = [ |
64
|
|
|
* 'scss' => [ |
65
|
|
|
* 'command' => '-I {path} --style compressed', |
66
|
|
|
* 'path' => '@root/tests/public/sourcepath/sass' |
67
|
|
|
* ], |
68
|
|
|
* ]; |
69
|
|
|
*/ |
70
|
|
|
public array $converterOptions = [ |
71
|
|
|
'less' => null, |
72
|
|
|
'scss' => null, |
73
|
|
|
'sass' => null, |
74
|
|
|
'styl' => null, |
75
|
|
|
'coffee' => null, |
76
|
|
|
'ts' => null, |
77
|
|
|
]; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @var array List of asset bundle class names that this bundle depends on. |
81
|
|
|
* |
82
|
|
|
* For example: |
83
|
|
|
* |
84
|
|
|
* ```php |
85
|
|
|
* public array $depends = [ |
86
|
|
|
* Yiisoft\Yii\Bootstrap5\Assets\BootstrapAsset:class, |
87
|
|
|
* Yiisoft\Yii\Bulma\Asset\BulmaAsset:class, |
88
|
|
|
* ]: |
89
|
|
|
* ``` |
90
|
|
|
*/ |
91
|
|
|
public array $depends = []; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @var array List of JavaScript files that this bundle contains. |
95
|
|
|
* |
96
|
|
|
* Each JavaScript file can be specified in one of the following formats: |
97
|
|
|
* |
98
|
|
|
* - an absolute URL representing an external asset. For example, |
99
|
|
|
* `http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js` or |
100
|
|
|
* `//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js`. |
101
|
|
|
* - a relative path representing a local asset (e.g. `js/main.js`). The actual file path of a local asset can be |
102
|
|
|
* determined by prefixing {@see $basePath} to the relative path, and the actual URL of the asset can be |
103
|
|
|
* determined by prefixing {@see $baseUrl} to the relative path. |
104
|
|
|
* - an array, with the first entry being the URL or relative path as described before, and a list of key => value |
105
|
|
|
* pairs that will be used to overwrite {@see $jsOptions} settings for this entry. |
106
|
|
|
* |
107
|
|
|
* Note that only a forward slash "/" should be used as directory separator. |
108
|
|
|
*/ |
109
|
|
|
public array $js = []; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @var array The options that will be passed to {@see \Yiisoft\View\WebView::registerJsFile()} |
113
|
|
|
* when registering the JS files in this bundle. |
114
|
|
|
*/ |
115
|
|
|
public array $jsOptions = []; |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @var array JavaScript code blocks to be passed to {@see \Yiisoft\View\WebView::registerJs()}. |
119
|
|
|
*/ |
120
|
|
|
public array $jsStrings = []; |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @var array JavaScript variables to be passed to {@see \Yiisoft\View\WebView::registerJsVar()}. |
124
|
|
|
*/ |
125
|
|
|
public array $jsVar = []; |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @var array The options to be passed to {@see AssetPublisherInterface::publish()} when the asset bundle |
129
|
|
|
* is being published. This property is used only when {@see $sourcePath} is set. |
130
|
|
|
*/ |
131
|
|
|
public array $publishOptions = []; |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @var string[] List of file paths to export into a format readable |
135
|
|
|
* by third party tools such as Webpack. See {@see AssetManager::export()}. |
136
|
|
|
* |
137
|
|
|
* If the array is empty, the file paths from the {@see $css} and {@see $js} |
138
|
|
|
* will be exported. See {@see AssetUtil::extractFilePathsForExport()}. |
139
|
|
|
* |
140
|
|
|
* For example: |
141
|
|
|
* |
142
|
|
|
* ```php |
143
|
|
|
* public array $export = [ |
144
|
|
|
* 'img/image.png', |
145
|
|
|
* 'css/style.css', |
146
|
|
|
* 'js/script.js', |
147
|
|
|
* ]: |
148
|
|
|
* ``` |
149
|
|
|
*/ |
150
|
|
|
public array $export = []; |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @var string|null The directory that contains the source asset files for this asset bundle. |
154
|
|
|
* A source asset file is a file that is part of your source code repository of your Web application. |
155
|
|
|
* You must set this property if the directory containing the source asset files is not Web accessible. |
156
|
|
|
* |
157
|
|
|
* If a publisher is set via {@see AssetManager::setPublisher()}, {@see AssetManager} will publish |
158
|
|
|
* the source asset files to a Web-accessible directory automatically when the asset bundle is registered on a page. |
159
|
|
|
* |
160
|
|
|
* If you do not set this property, it means the source asset files are located under {@see $basePath}. |
161
|
|
|
* |
162
|
|
|
* You can use either a directory or an alias of the directory. |
163
|
|
|
* |
164
|
|
|
* {@see $publishOptions} |
165
|
|
|
*/ |
166
|
|
|
public ?string $sourcePath = null; |
167
|
|
|
} |
168
|
|
|
|