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
파일 보기 프로젝트 열기: yiisoft/yii2 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$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