Craft 3 Class Reference

Class craft\web\AssetManager

Inheritance
craft\web\AssetManager » yii\web\AssetManager » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Available since version
3.0
Source Code
https://github.com/craftcms/cms/blob/master/src/web/AssetManager.php

Public Properties
Property Type Description Defined By
$afterCopy callback A PHP callback that is called after a sub-directory or file is successfully copied. yii\web\AssetManager
$appendTimestamp boolean Whether to append a timestamp to the URL of every published asset. yii\web\AssetManager
$assetMap array Mapping from source asset files (keys) to target asset files (values). yii\web\AssetManager
$basePath string The root directory storing the published asset files. yii\web\AssetManager
$baseUrl string The base URL through which the published asset files can be accessed. yii\web\AssetManager
$beforeCopy callback A PHP callback that is called before copying each sub-directory or file. yii\web\AssetManager
$bundles array, boolean List of asset bundle configurations. yii\web\AssetManager
$dirMode integer The permission to be set for newly generated asset directories. yii\web\AssetManager
$fileMode integer The permission to be set for newly published asset files. yii\web\AssetManager
$forceCopy boolean Whether the directory being published should be copied even if it is found in the target directory. yii\web\AssetManager
$hashCallback callable A callback that will be called to produce hash for asset directory generation. yii\web\AssetManager
$linkAssets boolean Whether to use symbolic link to publish asset files. yii\web\AssetManager
Public Methods
Method Description Defined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__unset() Sets an object property to null. yii\base\BaseObject
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\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
className() Returns the fully qualified name of this class. yii\base\BaseObject
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
getAssetPath() Returns the actual file path for the specified asset. yii\web\AssetManager
getAssetUrl() Returns the actual URL for the specified asset. yii\web\AssetManager
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getBundle() Returns the named asset bundle. yii\web\AssetManager
getConverter() Returns the asset converter. yii\web\AssetManager
getPublishedPath() Returns the published path of a file/directory path. craft\web\AssetManager
getPublishedUrl() Returns the URL of a published file/directory path. craft\web\AssetManager
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\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
init() Initializes the object. yii\base\BaseObject
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
publish() Publishes a file or a directory. yii\web\AssetManager
setConverter() Sets the asset converter. yii\web\AssetManager
trigger() Triggers an event. yii\base\Component
Protected Methods
Method Description Defined By
hash() Generate a CRC32 hash for the directory path. Collisions are higher than MD5 but generates a much smaller hash string. craft\web\AssetManager
loadBundle() Loads asset bundle class by name. yii\web\AssetManager
loadDummyBundle() Loads dummy bundle by name. yii\web\AssetManager
publishDirectory() Publishes a directory. craft\web\AssetManager
publishFile() Publishes a file. craft\web\AssetManager
resolveAsset() yii\web\AssetManager

Method Details

getPublishedPath() public method #

Returns the published path of a file/directory path.

public string, false getPublishedPath ( $sourcePath, \craft\web\bool $publish false )
$sourcePath string Directory or file path being published
$publish boolean Whether the directory or file should be published, if not already
return string, false The published file or directory path, or false if $publish is false and the file or directory does not exist

getPublishedUrl() public method #

Returns the URL of a published file/directory path.

public string, false getPublishedUrl ( $sourcePath, \craft\web\bool $publish false, $filePath null )
$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.
return string, false The published URL for the file or directory, or false if $publish is false and the file or directory does not exist

hash() protected method #

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

protected string hash ( $path )
$path string String to be hashed.
return string Hashed string.

publishDirectory() protected method #

Publishes a directory.

protected string[] publishDirectory ( $src, $options )
$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.
return string[] The path directory and the URL that the asset is published as.
throws yii\base\InvalidArgumentException if the asset to be published does not exist.

publishFile() protected method #

Publishes a file.

protected string[] publishFile ( $src )
$src string The asset file to be published
return string[] The path and the URL that the asset is published as.
throws yii\base\InvalidArgumentException if the asset to be published does not exist.