Passed
Push — master ( 781931...9601bc )
by Alexander
02:28
created

AssetBundle::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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