PHP Класс yii\console\controllers\AssetController

Usage: 1. Create a configuration file using the template action: yii asset/template /path/to/myapp/config.php 2. Edit the created config file, adjusting it for your web application needs. 3. Run the 'compress' action, using created config: yii asset /path/to/myapp/config.php /path/to/myapp/config/assets_compressed.php 4. Adjust your web application config to use compressed assets. Note: in the console environment some path aliases like @webroot and @web may not exist, so corresponding paths inside the configuration should be specified directly. Note: by default this command relies on an external tools to perform actual files compression, check [[jsCompressor]] and [[cssCompressor]] for more details.
С версии: 2.0
Автор: Qiang Xue ([email protected])
Наследование: extends yii\console\Controller
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$bundles list of asset bundles to be compressed.
$cssCompressor CSS file compressor. If a string, it is treated as shell command template, which should contain placeholders {from} - source file name - and {to} - output file name. Otherwise, it is treated as PHP callback, which should perform the compression. Default value relies on usage of "YUI Compressor"
$defaultAction controller default action ID.
$deleteSource whether to delete asset source files after compression. This option affects only those bundles, which have [[\yii\web\AssetBundle::sourcePath]] is set.
$jsCompressor JavaScript file compressor. If a string, it is treated as shell command template, which should contain placeholders {from} - source file name - and {to} - output file name. Otherwise, it is treated as PHP callback, which should perform the compression. Default value relies on usage of "Closure Compiler"
$targets list of asset bundles, which represents output compressed files. You can specify the name of the output compressed file using 'css' and 'js' keys: For example: php 'app\config\AllAsset' => [ 'js' => 'js/all-{hash}.js', 'css' => 'css/all-{hash}.css', 'depends' => [ ... ], ] File names can contain placeholder "{hash}", which will be filled by the hash of the resulting file. You may specify several target bundles in order to compress different groups of assets. In this case you should use 'depends' key to specify, which bundles should be covered with particular target bundle. You may leave 'depends' to be empty for single bundle, which will compress all remaining bundles in this case. For example: php 'allShared' => [ 'js' => 'js/all-shared-{hash}.js', 'css' => 'css/all-shared-{hash}.css', 'depends' => [ Include all assets shared between 'backend' and 'frontend' 'yii\web\YiiAsset', 'app\assets\SharedAsset', ], ], 'allBackEnd' => [ 'js' => 'js/all-{hash}.js', 'css' => 'css/all-{hash}.css', 'depends' => [ Include only 'backend' assets: 'app\assets\AdminAsset' ], ], 'allFrontEnd' => [ 'js' => 'js/all-{hash}.js', 'css' => 'css/all-{hash}.css', 'depends' => [], // Include all remaining assets ],

Открытые методы

Метод Описание
actionCompress ( string $configFile, string $bundleFile ) Combines and compresses the asset files according to the given configuration.
actionTemplate ( string $configFile ) : integer Creates template of configuration file for [[actionCompress]].
combineCssFiles ( array $inputFiles, string $outputFile ) Combines CSS files into a single one.
combineJsFiles ( array $inputFiles, string $outputFile ) Combines JavaScript files into a single one.
getAssetManager ( ) : AssetManager Returns the asset manager instance.
setAssetManager ( AssetManager | array $assetManager ) Sets asset manager instance or configuration.

Защищенные методы

Метод Описание
adjustCssUrl ( string $cssContent, string $inputFilePath, string $outputFilePath ) : string Adjusts CSS content allowing URL references pointing to the original resources.
adjustDependency ( AssetBundle[] $targets, AssetBundle[] $bundles ) : AssetBundle[] Adjust dependencies between asset bundles in the way source bundles begin to depend on output ones.
buildTarget ( AssetBundle $target, string $type, AssetBundle[] $bundles ) Builds output asset bundle.
compressCssFiles ( array $inputFiles, string $outputFile ) Compresses given CSS files and combines them into the single one.
compressJsFiles ( array $inputFiles, string $outputFile ) Compresses given JavaScript files and combines them into the single one.
loadBundles ( string[] $bundles ) : AssetBundle[] Creates full list of source asset bundles.
loadConfiguration ( string $configFile ) Applies configuration from the given file to self instance.
loadDependency ( AssetBundle $bundle, array &$result ) Loads asset bundle dependencies recursively.
loadTargets ( array $targets, AssetBundle[] $bundles ) : AssetBundle[] Creates full list of output asset bundles.
registerBundle ( AssetBundle[] $bundles, string $name, array &$registered ) Registers asset bundles including their dependencies.
saveTargets ( AssetBundle[] $targets, string $bundleFile ) Saves new asset bundles configuration.

Приватные методы

Метод Описание
composeBundleConfig ( AssetBundle $bundle ) : array
composeCircularDependencyTrace ( string $circularDependencyName, array $registered ) : string Composes trace info for bundle circular dependency.
deletePublishedAssets ( AssetBundle[] $bundles ) Deletes bundle asset files, which have been published from sourcePath.
findRealPath ( string $path ) : string Returns canonicalized absolute pathname.
isBundleExternal ( AssetBundle $bundle ) : boolean

Описание методов

actionCompress() публичный Метод

During the process new asset bundle configuration file will be created. You should replace your original asset bundle configuration with this file in order to use compressed files.
public actionCompress ( string $configFile, string $bundleFile )
$configFile string configuration file name.
$bundleFile string output asset bundles configuration file name.

actionTemplate() публичный Метод

Creates template of configuration file for [[actionCompress]].
public actionTemplate ( string $configFile ) : integer
$configFile string output file name.
Результат integer CLI exit code

adjustCssUrl() защищенный Метод

Adjusts CSS content allowing URL references pointing to the original resources.
protected adjustCssUrl ( string $cssContent, string $inputFilePath, string $outputFilePath ) : string
$cssContent string source CSS content.
$inputFilePath string input CSS file name.
$outputFilePath string output CSS file name.
Результат string adjusted CSS content.

adjustDependency() защищенный Метод

Adjust dependencies between asset bundles in the way source bundles begin to depend on output ones.
protected adjustDependency ( AssetBundle[] $targets, AssetBundle[] $bundles ) : AssetBundle[]
$targets yii\web\AssetBundle[] output asset bundles.
$bundles yii\web\AssetBundle[] source asset bundles.
Результат yii\web\AssetBundle[] output asset bundles.

buildTarget() защищенный Метод

Builds output asset bundle.
protected buildTarget ( AssetBundle $target, string $type, AssetBundle[] $bundles )
$target yii\web\AssetBundle output asset bundle
$type string either 'js' or 'css'.
$bundles yii\web\AssetBundle[] source asset bundles.

combineCssFiles() публичный Метод

Combines CSS files into a single one.
public combineCssFiles ( array $inputFiles, string $outputFile )
$inputFiles array source file names.
$outputFile string output file name.

combineJsFiles() публичный Метод

Combines JavaScript files into a single one.
public combineJsFiles ( array $inputFiles, string $outputFile )
$inputFiles array source file names.
$outputFile string output file name.

compressCssFiles() защищенный Метод

Compresses given CSS files and combines them into the single one.
protected compressCssFiles ( array $inputFiles, string $outputFile )
$inputFiles array list of source file names.
$outputFile string output file name.

compressJsFiles() защищенный Метод

Compresses given JavaScript files and combines them into the single one.
protected compressJsFiles ( array $inputFiles, string $outputFile )
$inputFiles array list of source file names.
$outputFile string output file name.

getAssetManager() публичный Метод

Returns the asset manager instance.
public getAssetManager ( ) : AssetManager
Результат yii\web\AssetManager asset manager instance.

loadBundles() защищенный Метод

Creates full list of source asset bundles.
protected loadBundles ( string[] $bundles ) : AssetBundle[]
$bundles string[] list of asset bundle names
Результат yii\web\AssetBundle[] list of source asset bundles.

loadConfiguration() защищенный Метод

Applies configuration from the given file to self instance.
protected loadConfiguration ( string $configFile )
$configFile string configuration file name.

loadDependency() защищенный Метод

Loads asset bundle dependencies recursively.
protected loadDependency ( AssetBundle $bundle, array &$result )
$bundle yii\web\AssetBundle bundle instance
$result array already loaded bundles list.

loadTargets() защищенный Метод

Creates full list of output asset bundles.
protected loadTargets ( array $targets, AssetBundle[] $bundles ) : AssetBundle[]
$targets array output asset bundles configuration.
$bundles yii\web\AssetBundle[] list of source asset bundles.
Результат yii\web\AssetBundle[] list of output asset bundles.

registerBundle() защищенный Метод

Registers asset bundles including their dependencies.
protected registerBundle ( AssetBundle[] $bundles, string $name, array &$registered )
$bundles yii\web\AssetBundle[] asset bundles list.
$name string bundle name.
$registered array stores already registered names.

saveTargets() защищенный Метод

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.

setAssetManager() публичный Метод

Sets asset manager instance or configuration.
public setAssetManager ( AssetManager | array $assetManager )
$assetManager yii\web\AssetManager | array asset manager instance or its array configuration.

Описание свойств

$bundles публичное свойство

list of asset bundles to be compressed.
public $bundles

$cssCompressor публичное свойство

CSS file compressor. If a string, it is treated as shell command template, which should contain placeholders {from} - source file name - and {to} - output file name. Otherwise, it is treated as PHP callback, which should perform the compression. Default value relies on usage of "YUI Compressor"
См. также: https://github.com/yui/yuicompressor/
public $cssCompressor

$defaultAction публичное свойство

controller default action ID.
public $defaultAction

$deleteSource публичное свойство

whether to delete asset source files after compression. This option affects only those bundles, which have [[\yii\web\AssetBundle::sourcePath]] is set.
С версии: 2.0.10
public $deleteSource

$jsCompressor публичное свойство

JavaScript file compressor. If a string, it is treated as shell command template, which should contain placeholders {from} - source file name - and {to} - output file name. Otherwise, it is treated as PHP callback, which should perform the compression. Default value relies on usage of "Closure Compiler"
См. также: https://developers.google.com/closure/compiler/
public $jsCompressor

$targets публичное свойство

list of asset bundles, which represents output compressed files. You can specify the name of the output compressed file using 'css' and 'js' keys: For example: php 'app\config\AllAsset' => [ 'js' => 'js/all-{hash}.js', 'css' => 'css/all-{hash}.css', 'depends' => [ ... ], ] File names can contain placeholder "{hash}", which will be filled by the hash of the resulting file. You may specify several target bundles in order to compress different groups of assets. In this case you should use 'depends' key to specify, which bundles should be covered with particular target bundle. You may leave 'depends' to be empty for single bundle, which will compress all remaining bundles in this case. For example: php 'allShared' => [ 'js' => 'js/all-shared-{hash}.js', 'css' => 'css/all-shared-{hash}.css', 'depends' => [ Include all assets shared between 'backend' and 'frontend' 'yii\web\YiiAsset', 'app\assets\SharedAsset', ], ], 'allBackEnd' => [ 'js' => 'js/all-{hash}.js', 'css' => 'css/all-{hash}.css', 'depends' => [ Include only 'backend' assets: 'app\assets\AdminAsset' ], ], 'allFrontEnd' => [ 'js' => 'js/all-{hash}.js', 'css' => 'css/all-{hash}.css', 'depends' => [], // Include all remaining assets ],
public $targets