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.0
# Public Properties
Property | Description |
---|---|
afterCopy | callback – A PHP callback that is called after a sub-directory or file is successfully copied. |
appendTimestamp | boolean – Whether to append a timestamp to the URL of every published asset. |
assetMap | array – Mapping from source asset files (keys) to target asset files (values). |
basePath | string – The root directory storing the published asset files. |
baseUrl | string – The base URL through which the published asset files can be accessed. |
beforeCopy | callback – A PHP callback that is called before copying each sub-directory or file. |
behaviors | yii\base\Behavior – List of behaviors attached to this component |
bundles | array, boolean – List of asset bundle configurations. |
converter | yii\web\AssetConverterInterface – The asset converter. |
dirMode | integer – The permission to be set for newly generated asset directories. |
fileMode | integer – The permission to be set for newly published asset files. |
forceCopy | boolean – Whether the directory being published should be copied even if it is found in the target directory. |
hashCallback | callable – A callback that will be called to produce hash for asset directory generation. |
linkAssets | boolean – Whether to use symbolic link to publish asset files. |
# Public Methods
Method | Description |
---|---|
__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.
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
# getPublishedUrl()
Returns the URL of a published file/directory path.
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
# 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() | 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.
Arguments
$path
(string) – String to be hashed.
Returns
string – Hashed string.
# publishDirectory()
Publishes a directory.
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
- yii\base\InvalidArgumentException
if the asset to be published does not exist.
# publishFile()
Publishes a file.
Arguments
$src
(string) – The asset file to be published
Returns
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.