AssetManager

Type
Class
Namespace
craft\web
Inherits
craft\web\AssetManager » yii\web\AssetManager » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Since
3.0

View source

Public Properties

PropertyDescription
$afterCopycallback – A PHP callback that is called after a sub-directory or file is successfully copied.
$appendTimestampboolean – Whether to append a timestamp to the URL of every published asset.
$assetMaparray – Mapping from source asset files (keys) to target asset files (values).
$basePathstring – The root directory storing the published asset files.
$baseUrlstring – The base URL through which the published asset files can be accessed.
$beforeCopycallback – A PHP callback that is called before copying each sub-directory or file.
$behaviorsyii\base\Behavior – List of behaviors attached to this component
$bundlesarray, boolean – List of asset bundle configurations.
$converteryii\web\AssetConverterInterface – The asset converter.
$dirModeinteger – The permission to be set for newly generated asset directories.
$fileModeinteger – The permission to be set for newly published asset files.
$forceCopyboolean – Whether the directory being published should be copied even if it is found in the target directory.
$hashCallbackcallable – A callback that will be called to produce hash for asset directory generation.
$linkAssetsboolean – Whether to use symbolic link to publish asset files.

Public Methods

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

getPublishedPath()

Returns the published path of a file/directory path.

View source

Arguments

  • $sourcePath (string) – Directory or file path being published
  • $publish (boolean) – Whether the directory or file should be published, if not already

Returns

string, false – The published file or directory path, or false if $publish is false and the file or directory does not exist

Signature

public string, false getPublishedPath ( $sourcePath, \craft\web\bool $publish = false )

getPublishedUrl()

Returns the URL of a published file/directory path.

View source

Arguments

  • $sourcePath (string) – Directory or file path being published
  • $publish (boolean) – Whether the directory or file should be published, if not already
  • $filePath (string, null) – A file path, relative to $sourcePath if $sourcePath is a directory, that should be appended to the returned URL.

Returns

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

Signature

public string, false getPublishedUrl ( $sourcePath, \craft\web\bool $publish = false, $filePath = null )

Protected Methods

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

hash()

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

View source

Arguments

  • $path (string) – String to be hashed.

Returns

string – Hashed string.

Signature

protected string hash ( $path )

publishDirectory()

Publishes a directory.

View source

Arguments

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

  • $options (array) – 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 if set.

  • afterCopy: callback, a PHP callback that is called after a sub-directory or file is successfully copied. This overrides $afterCopy 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 if set.

Returns

string[] – The path directory and the URL that the asset is published as.

Throws

Signature

protected string[] publishDirectory ( $src, $options )

publishFile()

Publishes a file.

View source

Arguments

  • $src (string) – The asset file to be published

Returns

string[] – The path and the URL that the asset is published as.

Throws

Signature

protected string[] publishFile ( $src )