PHP Class yii\web\AssetConverter

It is used by AssetManager to convert files after they have been published.
Since: 2.0
Author: Qiang Xue ([email protected])
Inheritance: extends yii\base\Component, implements yii\web\AssetConverterInterface
Show file Open project: yiisoft/yii2 Class Usage Examples

Public Properties

Property Type Description
$commands the commands that are used to perform the asset conversion. The keys are the asset file extension names, and the values are the corresponding target script types (either "css" or "js") and the commands used for the conversion. You may also use a path alias to specify the location of the command: php [ 'styl' => ['css', '@app/node_modules/bin/stylus < {from} > {to}'], ]
$forceConvert whether the source asset file should be converted even if its result already exists. You may want to set this to be true during the development stage to make sure the converted assets are always up-to-date. Do not set this to true on production servers as it will significantly degrade the performance.

Public Methods

Method Description
convert ( string $asset, string $basePath ) : string Converts a given asset file into a CSS or JS file.

Protected Methods

Method Description
runCommand ( string $command, string $basePath, string $asset, string $result ) : boolean Runs a command to convert asset files.

Method Details

convert() public method

Converts a given asset file into a CSS or JS file.
public convert ( string $asset, string $basePath ) : string
$asset string the asset file path, relative to $basePath
$basePath string the directory the $asset is relative to.
return string the converted asset file path, relative to $basePath.

runCommand() protected method

Runs a command to convert asset files.
protected runCommand ( string $command, string $basePath, string $asset, string $result ) : boolean
$command string the command to run. If prefixed with an `@` it will be treated as a path alias.
$basePath string asset base path and command working directory
$asset string the name of the asset file
$result string the name of the file to be generated by the converter command
return boolean true on success, false on failure. Failures will be logged.

Property Details

$commands public property

the commands that are used to perform the asset conversion. The keys are the asset file extension names, and the values are the corresponding target script types (either "css" or "js") and the commands used for the conversion. You may also use a path alias to specify the location of the command: php [ 'styl' => ['css', '@app/node_modules/bin/stylus < {from} > {to}'], ]
public $commands

$forceConvert public property

whether the source asset file should be converted even if its result already exists. You may want to set this to be true during the development stage to make sure the converted assets are always up-to-date. Do not set this to true on production servers as it will significantly degrade the performance.
public $forceConvert