Class cakebake\lessphp\AssetConverter

Inheritancecakebake\lessphp\AssetConverter » yii\web\AssetConverter » yii\base\Component » yii\base\Object
Implementsyii\base\Configurable, yii\web\AssetConverterInterface
Available since version2.0

AssetConverter supports conversion of less script format into CSS script.

It is used by \cakebake\lessphp\AssetManager to convert files after they have been published.

See also https://github.com/oyejorge/less.php.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$behaviors yii\base\Behavior[] List of behaviors attached to this component yii\base\Component
$cacheDir string|null Is passed to the SetCacheDir() method. cakebake\lessphp\AssetConverter
$cacheSuffix boolean Filename suffix to avoid the browser cache and force recompiling by configuration changes cakebake\lessphp\AssetConverter
$commands array The commands that are used to perform the asset conversion. yii\web\AssetConverter
$compress boolean You can tell less. cakebake\lessphp\AssetConverter
$forceConvert boolean Whether the source asset file should be converted even if its result already exists. yii\web\AssetConverter
$useCache boolean Less. cakebake\lessphp\AssetConverter

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. yii\base\Component
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. yii\base\Object
__get() Returns the value of a component property. yii\base\Component
__isset() Checks if a property is set, i.e. defined and not null. yii\base\Component
__set() Sets the value of a component property. yii\base\Component
__unset() Sets a component property to be null. yii\base\Component
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
canGetProperty() Returns a value indicating whether a property can be read. yii\base\Component
canSetProperty() Returns a value indicating whether a property can be set. yii\base\Component
className() Returns the fully qualified name of this class. yii\base\Object
convert() Converts a given LESS assets file into a CSS cakebake\lessphp\AssetConverter
detachBehavior() Detaches a behavior from the component. yii\base\Component
detachBehaviors() Detaches all behaviors from the component. yii\base\Component
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. yii\base\Component
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event. yii\base\Component
hasMethod() Returns a value indicating whether a method is defined. yii\base\Component
hasProperty() Returns a value indicating whether a property is defined for this component. yii\base\Component
init() Initializes the object. yii\base\Object
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
trigger() Triggers an event. yii\base\Component

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
buildResult() Builds the result file name cakebake\lessphp\AssetConverter
parseLess() Parsing Less File cakebake\lessphp\AssetConverter
runCommand() Runs a command to convert asset files. yii\web\AssetConverter

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
INPUT_EXT 'less' cakebake\lessphp\AssetConverter
OUTPUT_EXT 'css' cakebake\lessphp\AssetConverter

Property Details

$cacheDir public property

Is passed to the SetCacheDir() method. By default "cakebake\lessphp\runtime" is used.

public string|null $cacheDir null
$cacheSuffix public property

Filename suffix to avoid the browser cache and force recompiling by configuration changes

public boolean $cacheSuffix false
$compress public property

You can tell less.php to remove comments and whitespace to generate minimized css files.

public boolean $compress false
$useCache public property

Less.php will save serialized parser data for each .less file. Faster, but more memory-intense.

public boolean $useCache false

Method Details

buildResult() protected method

Builds the result file name

protected string buildResult ( $asset, $dotPos null, $resultSuffix null )
$asset string

The asset file path, relative to $basePath

$dotPos integer

The strrpos position of filename-extension dot

$resultSuffix mixed

Suffix result css filename

return string

The converted asset file path, relative to $basePath.

convert() public method

Converts a given LESS assets file into a CSS

public string convert ( $asset, $basePath )
$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.

parseLess() protected method

Parsing Less File

protected boolean parseLess ( $basePath, $asset, $result )
$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.

throws \cakebake\lessphp\Less_Exception_Parser

when the command fails