AssetManager

Type
Class
Namespace
craft\web
Inherits
craft\web\AssetManager » yii\web\AssetManager (opens new window) » yii\base\Component (opens new window) » yii\base\BaseObject (opens new window)
Implements
yii\base\Configurable (opens new window)
Since
3.0.0

View source (opens new window)

# Public Properties

Property Description
afterCopy (opens new window) callback – A PHP callback that is called after a sub-directory or file is successfully copied.
appendTimestamp (opens new window) boolean (opens new window) – Whether to append a timestamp to the URL of every published asset.
assetMap (opens new window) array (opens new window) – Mapping from source asset files (keys) to target asset files (values).
basePath (opens new window) string (opens new window) – The root directory storing the published asset files.
baseUrl (opens new window) string (opens new window) – The base URL through which the published asset files can be accessed.
beforeCopy (opens new window) callback – A PHP callback that is called before copying each sub-directory or file.
behaviors (opens new window) yii\base\Behavior (opens new window) – List of behaviors attached to this component
bundles (opens new window) array (opens new window), boolean (opens new window) – List of asset bundle configurations.
converter (opens new window) yii\web\AssetConverterInterface (opens new window) – The asset converter.
dirMode (opens new window) integer (opens new window) – The permission to be set for newly generated asset directories.
fileMode (opens new window) integer (opens new window) – The permission to be set for newly published asset files.
forceCopy (opens new window) boolean (opens new window) – Whether the directory being published should be copied even if it is found in the target directory.
hashCallback (opens new window) callable (opens new window) – A callback that will be called to produce hash for asset directory generation.
linkAssets (opens new window) boolean (opens new window) – Whether to use symbolic link to publish asset files.

# Public Methods

Method Description
__call() (opens new window) Calls the named method which is not a class method.
__clone() (opens new window) This method is called after the object is created by cloning an existing one.
__construct() (opens new window) Constructor.
__get() (opens new window) Returns the value of an object property.
__isset() (opens new window) Checks if a property is set, i.e. defined and not null.
__set() (opens new window) Sets value of an object property.
__unset() (opens new window) Sets an object property to null.
attachBehavior() (opens new window) Attaches a behavior to this component.
attachBehaviors() (opens new window) Attaches a list of behaviors to the component.
behaviors() (opens new window) Returns a list of behaviors that this component should behave as.
canGetProperty() (opens new window) Returns a value indicating whether a property can be read.
canSetProperty() (opens new window) Returns a value indicating whether a property can be set.
className() (opens new window) Returns the fully qualified name of this class.
detachBehavior() (opens new window) Detaches a behavior from the component.
detachBehaviors() (opens new window) Detaches all behaviors from the component.
ensureBehaviors() (opens new window) Makes sure that the behaviors declared in behaviors() (opens new window) are attached to this component.
getAssetPath() (opens new window) Returns the actual file path for the specified asset.
getAssetUrl() (opens new window) Returns the actual URL for the specified asset.
getBehavior() (opens new window) Returns the named behavior object.
getBehaviors() (opens new window) Returns all behaviors attached to this component.
getBundle() (opens new window) Returns the named asset bundle.
getConverter() (opens new window) Returns the asset converter.
getPublishedPath() Returns the published path of a file/directory path.
getPublishedUrl() Returns the URL of a published file/directory path.
hasEventHandlers() (opens new window) Returns a value indicating whether there is any handler attached to the named event.
hasMethod() (opens new window) Returns a value indicating whether a method is defined.
hasProperty() (opens new window) Returns a value indicating whether a property is defined.
init() (opens new window) Initializes the object.
off() (opens new window) Detaches an existing event handler from this component.
on() (opens new window) Attaches an event handler to an event.
publish() (opens new window) Publishes a file or a directory.
setConverter() (opens new window) Sets the asset converter.
trigger() (opens new window) Triggers an event.

# getPublishedPath()

Returns the published path of a file/directory path.

View source (opens new window)

Arguments

Returns

string (opens new window), false (opens new window) – The published file or directory path, or false if $publish is false and the file or directory does not exist

# getPublishedUrl()

Returns the URL of a published file/directory path.

View source (opens new window)

Arguments

Returns

string (opens new window), false (opens new window) – The published URL for the file or directory, or false if $publish is false and the file or directory does not exist

# Protected Methods

Method Description
hash() Generate a CRC32 hash for the directory path. Collisions are higher than MD5 but generates a much smaller hash string.
loadBundle() (opens new window) Loads asset bundle class by name.
loadDummyBundle() (opens new window) Loads dummy bundle by name.
publishDirectory() Publishes a directory.
publishFile() Publishes a file.
resolveAsset() (opens new window)

# hash()

Generate a CRC32 hash for the directory path. Collisions are higher than MD5 but generates a much smaller hash string.

View source (opens new window)

Arguments

Returns

string (opens new window) – Hashed string.

# publishDirectory()

Publishes a directory.

View source (opens new window)

Arguments

  • $src (string (opens new window)) – The asset directory to be published

  • $options (array (opens new window)) – The options to be applied when publishing a directory. The following options are supported:

  • only: array, list of patterns that the file paths should match if they want to be copied.

  • except: array, list of patterns that the files or directories should match if they want to be excluded from being copied.

  • caseSensitive: boolean, whether patterns specified at "only" or "except" should be case sensitive. Defaults to true.

  • beforeCopy: callback, a PHP callback that is called before copying each sub-directory or file. This overrides beforeCopy (opens new window) if set.

  • afterCopy: callback, a PHP callback that is called after a sub-directory or file is successfully copied. This overrides afterCopy (opens new window) if set.

  • forceCopy: boolean, whether the directory being published should be copied even if it is found in the target directory. This option is used only when publishing a directory. This overrides forceCopy (opens new window) if set.

Returns

string (opens new window)[] – The path directory and the URL that the asset is published as.

Throws

# publishFile()

Publishes a file.

View source (opens new window)

Arguments

Returns

string (opens new window)[] – The path and the URL that the asset is published as.

Throws