# AssetManager

> AssetManager manages asset bundle configuration and loading.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [web](/docs/api/yii/web/index.md) › AssetManager

| class | `yii\web\AssetManager` |
| --- | --- |
| Extends | [`yii\base\Component`](/docs/api/yii/base/component/index.md) » [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Since | 2.0 |
| Source | [`framework/web/AssetManager.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/web/AssetManager.php#L54) |

AssetManager manages asset bundle configuration and loading.

AssetManager is configured as an application component in [`Application`](/docs/api/yii/web/application/index.md) by default.
You can access that instance via `Yii::$app->assetManager`.

You can modify its configuration by adding an array to your application config under `components`
as shown in the following example:

```
'assetManager' => [
    'bundles' => [
        // you can override AssetBundle configs here
    ],
]
```

For more details and usage information on AssetManager, see the [guide article on assets](/docs/guide/structure-assets/index.md).

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| [`$afterCopy`](#property-afterCopy) | `callable\|null` | A PHP callback that is called after a sub-directory or file is successfully copied. Default: `null`. | `AssetManager` |
| [`$appendTimestamp`](#property-appendTimestamp) | `bool` | Whether to append a timestamp to the URL of every published asset. Default: `false`. Available since 2.0.3. | `AssetManager` |
| [`$assetMap`](#property-assetMap) | `string[]` | Mapping from source asset files (keys) to target asset files (values). Default: `[]`. | `AssetManager` |
| <span id="property-basePath"></span>`$basePath` | `string` | The root directory storing the published asset files. Default: `'@webroot/assets'`. | `AssetManager` |
| <span id="property-baseUrl"></span>`$baseUrl` | `string` | The base URL through which the published asset files can be accessed. Default: `'@web/assets'`. | `AssetManager` |
| [`$beforeCopy`](#property-beforeCopy) | `callable\|null` | A PHP callback that is called before copying each sub-directory or file. Default: `null`. | `AssetManager` |
| <span id="property-behaviors"></span>[`$behaviors`](/docs/api/yii/base/component/index.md#property-behaviors) read-only | `array<`[`yii\base\Behavior`](/docs/api/yii/base/behavior/index.md)`<static>>` | List of behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`$bundles`](#property-bundles) | `array\|false` | List of asset bundle configurations. Default: `[]`. | `AssetManager` |
| [`$converter`](#property-converter) | `array\|string\|`[`AssetConverterInterface`](/docs/api/yii/web/assetconverterinterface/index.md) | The asset converter. | `AssetManager` |
| [`$dirMode`](#property-dirMode) | `int` | The permission to be set for newly generated asset directories. Default: `0775`. | `AssetManager` |
| [`$fileMode`](#property-fileMode) | `int\|null` | The permission to be set for newly published asset files. Default: `null`. | `AssetManager` |
| [`$forceCopy`](#property-forceCopy) | `bool` | Whether the directory being published should be copied even if it is found in the target directory. Default: `false`. | `AssetManager` |
| [`$hashCallback`](#property-hashCallback) | `callable\|null` | A callback that will be called to produce hash for asset directory generation. Default: `null`. Available since 2.0.6. | `AssetManager` |
| [`$linkAssets`](#property-linkAssets) | `bool` | Whether to use symbolic link to publish asset files. Default: `false`. | `AssetManager` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/base/baseobject/index.md#method-__construct) | Constructor. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/component/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__clone"></span>[`__clone()`](/docs/api/yii/base/component/index.md#method-__clone) | This method is called after the object is created by cloning an existing one. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/component/index.md#method-__get) | Returns the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/component/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/component/index.md#method-__set) | Sets the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/component/index.md#method-__unset) | Sets a component property to be null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-attachBehavior"></span>[`attachBehavior()`](/docs/api/yii/base/component/index.md#method-attachBehavior) | Attaches a behavior to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-attachBehaviors"></span>[`attachBehaviors()`](/docs/api/yii/base/component/index.md#method-attachBehaviors) | Attaches a list of behaviors to the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-behaviors"></span>[`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) | Returns a list of behaviors that this component should behave as. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/component/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/component/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`checkBasePathPermission()`](#method-checkBasePathPermission) | Check whether the basePath exists and is writeable. | `AssetManager` |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-detachBehavior"></span>[`detachBehavior()`](/docs/api/yii/base/component/index.md#method-detachBehavior) | Detaches a behavior from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-detachBehaviors"></span>[`detachBehaviors()`](/docs/api/yii/base/component/index.md#method-detachBehaviors) | Detaches all behaviors from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-ensureBehaviors"></span>[`ensureBehaviors()`](/docs/api/yii/base/component/index.md#method-ensureBehaviors) | Makes sure that the behaviors declared in [`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) are attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`getActualAssetUrl()`](#method-getActualAssetUrl) | Returns the actual URL for the specified asset. Without parameters. | `AssetManager` |
| [`getAssetPath()`](#method-getAssetPath) | Returns the actual file path for the specified asset. | `AssetManager` |
| [`getAssetUrl()`](#method-getAssetUrl) | Returns the actual URL for the specified asset. | `AssetManager` |
| <span id="method-getBehavior"></span>[`getBehavior()`](/docs/api/yii/base/component/index.md#method-getBehavior) | Returns the named behavior object. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getBehaviors"></span>[`getBehaviors()`](/docs/api/yii/base/component/index.md#method-getBehaviors) | Returns all behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`getBundle()`](#method-getBundle) | Returns the named asset bundle. | `AssetManager` |
| [`getConverter()`](#method-getConverter) | Returns the asset converter. | `AssetManager` |
| [`getPublishedPath()`](#method-getPublishedPath) | Returns the published path of a file path. | `AssetManager` |
| [`getPublishedUrl()`](#method-getPublishedUrl) | Returns the URL of a published file path. | `AssetManager` |
| <span id="method-hasEventHandlers"></span>[`hasEventHandlers()`](/docs/api/yii/base/component/index.md#method-hasEventHandlers) | Returns a value indicating whether there is any handler attached to the named event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/component/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/component/index.md#method-hasProperty) | Returns a value indicating whether a property is defined for this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`init()`](#method-init) | Initializes the component. | `AssetManager` |
| <span id="method-off"></span>[`off()`](/docs/api/yii/base/component/index.md#method-off) | Detaches an existing event handler from this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-on"></span>[`on()`](/docs/api/yii/base/component/index.md#method-on) | Attaches an event handler to an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`publish()`](#method-publish) | Publishes a file or a directory. | `AssetManager` |
| [`setConverter()`](#method-setConverter) | Sets the asset converter. | `AssetManager` |
| <span id="method-trigger"></span>[`trigger()`](/docs/api/yii/base/component/index.md#method-trigger) | Triggers an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`hash()`](#method-hash) protected | Generate a CRC32 hash for the directory path. Collisions are higher than MD5 but generates a much smaller hash string. | `AssetManager` |
| [`loadBundle()`](#method-loadBundle) protected | Loads asset bundle class by name. | `AssetManager` |
| [`loadDummyBundle()`](#method-loadDummyBundle) protected | Loads dummy bundle by name. | `AssetManager` |
| [`publishDirectory()`](#method-publishDirectory) protected | Publishes a directory. | `AssetManager` |
| [`publishFile()`](#method-publishFile) protected | Publishes a file. | `AssetManager` |
| [`resolveAsset()`](#method-resolveAsset) protected |  | `AssetManager` |

## Property details

### $afterCopy <span id="property-afterCopy"></span>

```php
public callable|null $afterCopy = null
```

A PHP callback that is called after a sub-directory or file is successfully copied.

This option is used only when publishing a directory. The signature of the callback is the same as
for [`$beforeCopy`](/docs/api/yii/web/assetmanager/index.md#property-beforeCopy).
This is passed as a parameter `afterCopy` to [`FileHelper::copyDirectory()`](/docs/api/yii/helpers/basefilehelper/index.md#method-copyDirectory).

### $appendTimestamp <span id="property-appendTimestamp"></span>

```php
public bool $appendTimestamp = false
```

Whether to append a timestamp to the URL of every published asset.

When this is true,
the URL of a published asset may look like `/path/to/asset?v=timestamp`, where `timestamp` is the
last modification time of the published asset file.
You normally would want to set this property to true when you have enabled HTTP caching for assets,
because it allows you to bust caching when the assets are updated.

**Since**

2.0.3

### $assetMap <span id="property-assetMap"></span>

```php
public string[] $assetMap = []
```

Mapping from source asset files (keys) to target asset files (values).

This property is provided to support fixing incorrect asset file paths in some asset bundles.
When an asset bundle is registered with a view, each relative asset file in its [css](/docs/api/yii/web/assetbundle/index.md#property-css)
and [js](/docs/api/yii/web/assetbundle/index.md#property-js) arrays will be examined against this map. If any of the keys is found
to be the last part of an asset file (which is prefixed with [`AssetBundle::$sourcePath`](/docs/api/yii/web/assetbundle/index.md#property-sourcePath) if available),
the corresponding value will replace the asset and be registered with the view.
For example, an asset file `my/path/to/jquery.js` matches a key `jquery.js`.

Note that the target asset files should be absolute URLs, domain relative URLs (starting from '/') or paths
relative to [`$baseUrl`](/docs/api/yii/web/assetmanager/index.md#property-baseUrl) and [`$basePath`](/docs/api/yii/web/assetmanager/index.md#property-basePath).

In the following example, any assets ending with `jquery.min.js` will be replaced with `jquery/dist/jquery.js`
which is relative to [`$baseUrl`](/docs/api/yii/web/assetmanager/index.md#property-baseUrl) and [`$basePath`](/docs/api/yii/web/assetmanager/index.md#property-basePath).

```
[
    'jquery.min.js' => 'jquery/dist/jquery.js',
]
```

You may also use aliases while specifying map value, for example:

```
[
    'jquery.min.js' => '@web/js/jquery/jquery.js',
]
```

### $beforeCopy <span id="property-beforeCopy"></span>

```php
public callable|null $beforeCopy = null
```

A PHP callback that is called before copying each sub-directory or file.

This option is used only when publishing a directory. If the callback returns false, the copy
operation for the sub-directory or file will be cancelled.

The signature of the callback should be: `function ($from, $to)`, where `$from` is the sub-directory or
file to be copied from, while `$to` is the copy target.

This is passed as a parameter `beforeCopy` to [`FileHelper::copyDirectory()`](/docs/api/yii/helpers/basefilehelper/index.md#method-copyDirectory).

### $bundles <span id="property-bundles"></span>

```php
public array|false $bundles = []
```

List of asset bundle configurations.

This property is provided to customize asset bundles.
When a bundle is being loaded by [`getBundle()`](/docs/api/yii/web/assetmanager/index.md#method-getBundle), if it has a corresponding configuration specified here,
the configuration will be applied to the bundle.

The array keys are the asset bundle names, which typically are asset bundle class names without leading backslash.
The array values are the corresponding configurations. If a value is false, it means the corresponding asset
bundle is disabled and [`getBundle()`](/docs/api/yii/web/assetmanager/index.md#method-getBundle) should return null.

If this property is false, it means the whole asset bundle feature is disabled and [`getBundle()`](/docs/api/yii/web/assetmanager/index.md#method-getBundle)
will always return null.

The following example shows how to override a specific asset bundle (e.g. to drop its CSS files, or to
redirect JS/CSS files to a CDN). Replace `app\assets\AppAsset` with the FQCN of the bundle you want to
customize:

```
[
    'app\assets\AppAsset' => [
        'css' => [],
    ],
]
```

To remap individual asset files (for example, to serve `jquery.js` from a CDN or a local build folder), use
[`$assetMap`](/docs/api/yii/web/assetmanager/index.md#property-assetMap) instead; it maps a source file name to its replacement URL and is resolved at publish/register time.

A bundle may also set its own [`AssetBundle::$sourcePath`](/docs/api/yii/web/assetbundle/index.md#property-sourcePath) to point the entire bundle at an alternate directory.

### $converter <span id="property-converter"></span>

```php
public array|string|yii\web\AssetConverterInterface $converter
```

The asset converter.

This can be either an
object implementing the [`AssetConverterInterface`](/docs/api/yii/web/assetconverterinterface/index.md), or a configuration array that can be used to create the
asset converter object, or a class name.

### $dirMode <span id="property-dirMode"></span>

```php
public int $dirMode = 0775
```

The permission to be set for newly generated asset directories.

This value will be used by PHP chmod() function. No umask will be applied.
Defaults to 0775, meaning the directory is read-writable by owner and group,
but read-only for other users.

### $fileMode <span id="property-fileMode"></span>

```php
public int|null $fileMode = null
```

The permission to be set for newly published asset files.

This value will be used by PHP chmod() function. No umask will be applied.
If not set, the permission will be determined by the current environment.

### $forceCopy <span id="property-forceCopy"></span>

```php
public bool $forceCopy = false
```

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.
You may want to set this to be `true` during the development stage to make sure the published
directory is always up-to-date. Do not set this to true on production servers as it will
significantly degrade the performance.

### $hashCallback <span id="property-hashCallback"></span>

```php
public callable|null $hashCallback = null
```

A callback that will be called to produce hash for asset directory generation.

The signature of the callback should be as follows:

```
function ($path)
```

where `$path` is the asset path. Note that the `$path` can be either directory where the asset
files reside or a single file. For a CSS file that uses relative path in `url()`, the hash
implementation should use the directory path of the file instead of the file path to include
the relative asset files in the copying.

If this is not set, the asset manager will use the default CRC32 and filemtime in the `hash`
method.

Example of an implementation using MD4 hash:

```
function ($path) {
    return hash('md4', $path);
}
```

**Since**

2.0.6

### $linkAssets <span id="property-linkAssets"></span>

```php
public bool $linkAssets = false
```

Whether to use symbolic link to publish asset files.

Defaults to false, meaning
asset files are copied to [`$basePath`](/docs/api/yii/web/assetmanager/index.md#property-basePath). Using symbolic links has the benefit that the published
assets will always be consistent with the source assets and there is no copy operation required.
This is especially useful during development.

However, there are special requirements for hosting environments in order to use symbolic links.
In particular, symbolic links are supported only on Linux/Unix, and Windows Vista/2008 or greater.

Moreover, some Web servers need to be properly configured so that the linked assets are accessible
to Web users. For example, for Apache Web server, the following configuration directive should be added
for the Web folder:

```
Options FollowSymLinks
```

## Method details

### checkBasePathPermission() <span id="method-checkBasePathPermission"></span>

```php
public function checkBasePathPermission(): mixed
```

Check whether the basePath exists and is writeable.

**Returns**

`mixed`

**Since**

2.0.40

### getActualAssetUrl() <span id="method-getActualAssetUrl"></span>

```php
public function getActualAssetUrl(yii\web\AssetBundle $bundle, string $asset): string
```

Returns the actual URL for the specified asset. Without parameters.

The actual URL is obtained by prepending either [`AssetBundle::$baseUrl`](/docs/api/yii/web/assetbundle/index.md#property-baseUrl) or [`AssetManager::$baseUrl`](/docs/api/yii/web/assetmanager/index.md#property-baseUrl) to the given asset path.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$bundle` | [`AssetBundle`](/docs/api/yii/web/assetbundle/index.md) | The asset bundle which the asset file belongs to |
| `$asset` | `string` | The asset path. This should be one of the assets listed in [`AssetBundle::$js`](/docs/api/yii/web/assetbundle/index.md#property-js) or [`AssetBundle::$css`](/docs/api/yii/web/assetbundle/index.md#property-css). |

**Returns**

`string`: The actual URL for the specified asset.

**Since**

2.0.39

### getAssetPath() <span id="method-getAssetPath"></span>

```php
public function getAssetPath(yii\web\AssetBundle $bundle, string $asset): string|false
```

Returns the actual file path for the specified asset.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$bundle` | [`AssetBundle`](/docs/api/yii/web/assetbundle/index.md) | The asset bundle which the asset file belongs to |
| `$asset` | `string` | The asset path. This should be one of the assets listed in [`AssetBundle::$js`](/docs/api/yii/web/assetbundle/index.md#property-js) or [`AssetBundle::$css`](/docs/api/yii/web/assetbundle/index.md#property-css). |

**Returns**

`string|false`: The actual file path, or `false` if the asset is specified as an absolute URL

### getAssetUrl() <span id="method-getAssetUrl"></span>

```php
public function getAssetUrl(yii\web\AssetBundle $bundle, string $asset, bool|null $appendTimestamp = null): string
```

Returns the actual URL for the specified asset.

The actual URL is obtained by prepending either [`AssetBundle::$baseUrl`](/docs/api/yii/web/assetbundle/index.md#property-baseUrl) or [`AssetManager::$baseUrl`](/docs/api/yii/web/assetmanager/index.md#property-baseUrl) to the given asset path.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$bundle` | [`AssetBundle`](/docs/api/yii/web/assetbundle/index.md) | The asset bundle which the asset file belongs to |
| `$asset` | `string` | The asset path. This should be one of the assets listed in [`AssetBundle::$js`](/docs/api/yii/web/assetbundle/index.md#property-js) or [`AssetBundle::$css`](/docs/api/yii/web/assetbundle/index.md#property-css). |
| `$appendTimestamp` | `bool\|null` | Whether to append timestamp to the URL. |

**Returns**

`string`: The actual URL for the specified asset.

### getBundle() <span id="method-getBundle"></span>

```php
public function getBundle(string $name, bool $publish = true): yii\web\AssetBundle
```

Returns the named asset bundle.

This method will first look for the bundle in [`$bundles`](/docs/api/yii/web/assetmanager/index.md#property-bundles). If not found,
it will treat `$name` as the class of the asset bundle and create a new instance of it.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The class name of the asset bundle (without the leading backslash) |
| `$publish` | `bool` | Whether to publish the asset files in the asset bundle before it is returned. If you set this false, you must manually call `AssetBundle::publish()` to publish the asset files. |

**Returns**

[`AssetBundle`](/docs/api/yii/web/assetbundle/index.md): The asset bundle instance

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): if $name does not refer to a valid asset bundle

### getConverter() <span id="method-getConverter"></span>

```php
public function getConverter(): yii\web\AssetConverterInterface
```

Returns the asset converter.

**Returns**

[`AssetConverterInterface`](/docs/api/yii/web/assetconverterinterface/index.md): The asset converter.

### getPublishedPath() <span id="method-getPublishedPath"></span>

```php
public function getPublishedPath(string $path): string|false
```

Returns the published path of a file path.

This method does not perform any publishing. It merely tells you
if the file or directory is published, where it will go.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$path` | `string` | Directory or file path being published |

**Returns**

`string|false`: String the published file path. False if the file or directory does not exist

### getPublishedUrl() <span id="method-getPublishedUrl"></span>

```php
public function getPublishedUrl(string $path): string|false
```

Returns the URL of a published file path.

This method does not perform any publishing. It merely tells you
if the file path is published, what the URL will be to access it.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$path` | `string` | Directory or file path being published |

**Returns**

`string|false`: String the published URL for the file or directory. False if the file or directory does not exist.

### init() <span id="method-init"></span>

```php
public function init(): mixed
```

Initializes the component.

**Returns**

`mixed`

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): if [`$basePath`](/docs/api/yii/web/assetmanager/index.md#property-basePath) does not exist.

### publish() <span id="method-publish"></span>

```php
public function publish(string $path, yii\web\PublishOptions $options = []): array
```

Publishes a file or a directory.

This method will copy the specified file or directory to [`$basePath`](/docs/api/yii/web/assetmanager/index.md#property-basePath) so that
it can be accessed via the Web server.

If the asset is a file, its file modification time will be checked to avoid
unnecessary file copying.

If the asset is a directory, all files and subdirectories under it will be published recursively.
Note, in case $forceCopy is false the method only checks the existence of the target
directory to avoid repetitive copying (which is very expensive).

By default, when publishing a directory, subdirectories and files whose name starts with a dot "."
will NOT be published. If you want to change this behavior, you may specify the "beforeCopy" option
as explained in the `$options` parameter.

Note: On rare scenario, a race condition can develop that will lead to a
one-time-manifestation of a non-critical problem in the creation of the directory
that holds the published assets. This problem can be avoided altogether by 'requesting'
in advance all the resources that are supposed to trigger a 'publish()' call, and doing
that in the application deployment phase, before system goes live. See more in the following
discussion: https://code.google.com/archive/p/yii/issues/2579

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$path` | `string` | The asset (file or directory) to be published |
| `$options` | `yii\web\PublishOptions` | 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`](/docs/api/yii/web/assetmanager/index.md#property-beforeCopy) if set. - afterCopy: callback, a PHP callback that is called after a sub-directory or file is successfully copied. This overrides [`$afterCopy`](/docs/api/yii/web/assetmanager/index.md#property-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`](/docs/api/yii/web/assetmanager/index.md#property-forceCopy) if set. |

**Returns**

`array`: The path (directory or file path) and the URL that the asset is published as.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the asset to be published does not exist.
- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): if the target directory [`$basePath`](/docs/api/yii/web/assetmanager/index.md#property-basePath) is not writeable.

### setConverter() <span id="method-setConverter"></span>

```php
public function setConverter(array|string|yii\web\AssetConverterInterface $value): mixed
```

Sets the asset converter.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `array\|string\|`[`AssetConverterInterface`](/docs/api/yii/web/assetconverterinterface/index.md) | The asset converter. This can be either an object implementing the [`AssetConverterInterface`](/docs/api/yii/web/assetconverterinterface/index.md), or a configuration array that can be used to create the asset converter object, or a class name. |

**Returns**

`mixed`

### hash() <span id="method-hash"></span>

```php
protected function hash(string $path): string
```

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

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$path` | `string` | String to be hashed. |

**Returns**

`string`: Hashed string.

### loadBundle() <span id="method-loadBundle"></span>

```php
protected function loadBundle(string $name, array $config = [], bool $publish = true): yii\web\AssetBundle
```

Loads asset bundle class by name.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | Bundle name |
| `$config` | `array` | Bundle object configuration |
| `$publish` | `bool` | If bundle should be published |

**Returns**

[`AssetBundle`](/docs/api/yii/web/assetbundle/index.md)

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): if configuration isn't valid

### loadDummyBundle() <span id="method-loadDummyBundle"></span>

```php
protected function loadDummyBundle(string $name): yii\web\AssetBundle
```

Loads dummy bundle by name.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` |  |

**Returns**

[`AssetBundle`](/docs/api/yii/web/assetbundle/index.md)

### publishDirectory() <span id="method-publishDirectory"></span>

```php
protected function publishDirectory(string $src, array $options): string[]
```

Publishes a directory.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$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`](/docs/api/yii/web/assetmanager/index.md#property-beforeCopy) if set. - afterCopy: callback, a PHP callback that is called after a sub-directory or file is successfully copied. This overrides [`$afterCopy`](/docs/api/yii/web/assetmanager/index.md#property-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`](/docs/api/yii/web/assetmanager/index.md#property-forceCopy) if set. |

**Returns**

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

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the asset to be published does not exist.

### publishFile() <span id="method-publishFile"></span>

```php
protected function publishFile(string $src): string[]
```

Publishes a file.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$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`](/docs/api/yii/base/invalidargumentexception/index.md): if the asset to be published does not exist.

### resolveAsset() <span id="method-resolveAsset"></span>

```php
protected function resolveAsset(yii\web\AssetBundle $bundle, string $asset): string|false
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$bundle` | [`AssetBundle`](/docs/api/yii/web/assetbundle/index.md) |  |
| `$asset` | `string` |  |

**Returns**

`string|false`