yii\console\controllers\AssetController::saveTargets PHP Method

saveTargets() protected method

Saves new asset bundles configuration.
protected saveTargets ( AssetBundle[] $targets, string $bundleFile )
$targets yii\web\AssetBundle[] list of asset bundles to be saved.
$bundleFile string output file name.
    protected function saveTargets($targets, $bundleFile)
    {
        $array = [];
        foreach ($targets as $name => $target) {
            if (isset($this->targets[$name])) {
                $array[$name] = array_merge($this->targets[$name], ['class' => get_class($target), 'sourcePath' => null, 'basePath' => $this->targets[$name]['basePath'], 'baseUrl' => $this->targets[$name]['baseUrl'], 'js' => $target->js, 'css' => $target->css, 'depends' => []]);
            } else {
                if ($this->isBundleExternal($target)) {
                    $array[$name] = $this->composeBundleConfig($target);
                } else {
                    $array[$name] = ['sourcePath' => null, 'js' => [], 'css' => [], 'depends' => $target->depends];
                }
            }
        }
        $array = VarDumper::export($array);
        $version = date('Y-m-d H:i:s', time());
        $bundleFileContent = <<<EOD
<?php
/**
 * This file is generated by the "yii {$this->id}" command.
 * DO NOT MODIFY THIS FILE DIRECTLY.
 * @version {$version}
 */
return {$array};
EOD;
        if (!file_put_contents($bundleFile, $bundleFileContent)) {
            throw new Exception("Unable to write output bundle configuration at '{$bundleFile}'.");
        }
        $this->stdout("Output bundle configuration created at '{$bundleFile}'.\n", Console::FG_GREEN);
    }