Final Class Yiisoft\Assets\Exporter\JsonAssetExporter
| Inheritance | Yiisoft\Assets\Exporter\JsonAssetExporter |
|---|---|
| Implements | Yiisoft\Assets\AssetExporterInterface |
Exports the file paths of asset bundles {@see AssetBundle::$export} to a JSON file.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Assets\Exporter\JsonAssetExporter | |
| export() | Exports asset bundle file paths {@see AssetBundle::$export}. | Yiisoft\Assets\Exporter\JsonAssetExporter |
Method Details
| public mixed __construct ( string $targetFile ) | ||
| $targetFile | string |
The full path to the target JSON file. |
public function __construct(
private readonly string $targetFile,
) {
}
Exports asset bundle file paths {@see AssetBundle::$export}.
All dependencies must be created, and path aliases for {@see \Yiisoft\Assets\AssetBundle} properties are resolved {@see \Yiisoft\Assets\AssetUtil::resolvePathAliases()}. When using {@see \Yiisoft\Assets\AssetManager::export()}, all dependencies and path aliases will be automatically resolved.
| public void export ( array $assetBundles ) | ||
| $assetBundles | array |
The asset bundle instances. |
| throws | RuntimeException |
If an error occurred while writing to the JSON file. |
|---|---|---|
public function export(array $assetBundles): void
{
try {
$data = Json::encode(AssetUtil::extractFilePathsForExport($assetBundles));
} catch (JsonException $e) {
throw new RuntimeException('An error occurred during JSON encoding of asset bundles.', 0, $e);
}
AssetUtil::exportToFile($this->targetFile, $data);
}
Signup or Login in order to comment.