WebAssetManager

Implements WebAssetManagerInterface

Web Asset Manager class

since

4.0.0

package

Joomla CMS

Methods

__call

Adds support for magic method calls

__call( method, mixed||string|int arguments) : 
throws

BadMethodCallException

since

4.0.0

Arguments

method

stringA method name

arguments

array<string|int, mixed>Arguments for a method

Response

mixed

__construct

Class constructor

__construct(\Joomla\CMS\WebAsset\WebAssetRegistry registry) : 
since

4.0.0

Arguments

registry

WebAssetRegistryThe WebAsset Registry instance

Response

mixed

addInline

Add a new inline content asset.

addInline( type, \Joomla\CMS\WebAsset\WebAssetItem|string content, mixed||string|int options = [], mixed||string|int attributes = [], mixed||string|int dependencies = []) : 

Allow to register WebAssetItem instance in the registry, by call addInline($type, $assetInstance) Or create an asset on fly (from name and Uri) and register in the registry, by call addInline($type, $content, $options ....)

since

4.0.0

throws

InvalidArgumentException

Arguments

type

stringThe asset type, script or style

content

WebAssetItem|stringThe content to of inline asset

options

array<string|int, mixed>Additional options for the asset

attributes

array<string|int, mixed>Attributes for the asset

dependencies

array<string|int, mixed>Asset dependencies

Response

self

addInlineScript

addInlineScript(\Joomla\CMS\WebAsset\WebAssetItem|string content,  options,  attributes,  dependencies) : \Joomla\CMS\WebAsset\WebAssetManager

Arguments

content

WebAssetItem|string

options

mixed

attributes

mixed

dependencies

mixed

Response

WebAssetManager

addInlineStyle

addInlineStyle(\Joomla\CMS\WebAsset\WebAssetItem|string content,  options,  attributes,  dependencies) : \Joomla\CMS\WebAsset\WebAssetManager

Arguments

content

WebAssetItem|string

options

mixed

attributes

mixed

dependencies

mixed

Response

WebAssetManager

assetExists

Helper method to check whether the asset exists in the registry.

assetExists( type,  name) : 
since

4.0.0

Arguments

type

stringAsset type, script or style

name

stringAsset name

Response

bool

calculateOrderOfActiveAssets

Calculate weight of active Assets, by its Dependencies

calculateOrderOfActiveAssets( type) : \Joomla\CMS\WebAsset\WebAssetItem||string|int
since

4.0.0

Arguments

type

stringThe asset type, script or style

Response

array<string|int, WebAssetItem>

disableAsset

Deactivate an asset item, so it will not be attached to a Document

disableAsset( type,  name) : 
throws

UnknownAssetExceptionWhen Asset cannot be found

InvalidActionExceptionWhen the Manager already attached to a Document

since

4.0.0

Arguments

type

stringThe asset type, script or style

name

stringThe asset name

Response

self

disablePreset

disablePreset( name) : \Joomla\CMS\WebAsset\WebAssetManager

Arguments

name

mixed

Response

WebAssetManager

disablePresetItems

Deactivate list of assets provided by Preset item.

disablePresetItems( name) : 
throws

UnsatisfiedDependencyExceptionWhen Asset dependency cannot be found

since

4.0.0

Arguments

name

stringThe asset name

Response

self

disableScript

disableScript( name) : \Joomla\CMS\WebAsset\WebAssetManager

Arguments

name

mixed

Response

WebAssetManager

disableStyle

disableStyle( name) : \Joomla\CMS\WebAsset\WebAssetManager

Arguments

name

mixed

Response

WebAssetManager

enableDependencies

Update Dependencies state for all active Assets or only for given

enableDependencies( type = null, \Joomla\CMS\WebAsset\WebAssetItem asset = null) : 
since

4.0.0

Arguments

type

stringThe asset type, script or style

asset

WebAssetItemThe asset instance to which need to enable dependencies

Response

self

filterOutInlineAssets

Helper method to filter an inline assets

filterOutInlineAssets(\Joomla\CMS\WebAsset\WebAssetItem||string|int &assets) : \Joomla\CMS\WebAsset\WebAssetItem||string|int
since

4.0.0

Arguments

assets

array<string|int, WebAssetItem>Reference to a full list of active assets

Response

array<string|int, WebAssetItem>Array of inline assets

getAsset

Helper method to get the asset from the registry.

getAsset( type,  name) : \Joomla\CMS\WebAsset\WebAssetItemInterface
throws

UnknownAssetExceptionWhen Asset cannot be found

since

4.0.0

Arguments

type

stringAsset type, script or style

name

stringAsset name

Response

WebAssetItemInterface

getAssets

Get all active assets, optionally sort them to follow the dependency Graph

getAssets( type,  sort = false) : \Joomla\CMS\WebAsset\WebAssetItem||string|int
throws

UnknownAssetExceptionWhen Asset cannot be found

UnsatisfiedDependencyExceptionWhen Dependency cannot be found

since

4.0.0

Arguments

type

stringThe asset type, script or style

sort

boolWhether need to sort the assets to follow the dependency Graph

Response

array<string|int, WebAssetItem>

getAssetState

Get a state for the Asset

getAssetState( type,  name) : 
throws

UnknownAssetExceptionWhen Asset cannot be found

since

4.0.0

Arguments

type

stringThe asset type, script or style

name

stringThe asset name

Response

int

getConnectionsGraph

Build Graph of Outgoing and Incoming connections for given assets.

getConnectionsGraph(\Joomla\CMS\WebAsset\WebAssetItem||string|int assets) : mixed||string|int
since

4.0.0

Arguments

assets

array<string|int, WebAssetItem>Asset instances

Response

array<string|int, mixed>

getDependenciesForAsset

Return dependencies for Asset as array of WebAssetItem objects

getDependenciesForAsset( type, \Joomla\CMS\WebAsset\WebAssetItem asset,  recursively = false,  recursionType = null, \Joomla\CMS\WebAsset\WebAssetItem recursionRoot = null) : mixed||string|int
throws

UnsatisfiedDependencyExceptionWhen Dependency cannot be found

since

4.0.0

Arguments

type

stringThe asset type, script or style

asset

WebAssetItemAsset instance

recursively

boolWhether to search for dependency recursively

recursionType

stringThe type of initial item to prevent loop

recursionRoot

WebAssetItemInitial item to prevent loop

Response

array<string|int, mixed>

getInlineRelation

Helper method to calculate inline to non inline relation (before/after positions).

getInlineRelation(\Joomla\CMS\WebAsset\WebAssetItem||string|int assets) : mixed||string|int

Return associated array, which contain dependency (handle) name as key, and list of inline items for each position. Example: ['handle.name' => ['before' => ['inline1', 'inline2'], 'after' => ['inline3', 'inline4']]]

Note: If inline asset have a multiple dependencies, then will be used last one from the list for positioning

since

4.0.0

Arguments

assets

array<string|int, WebAssetItem>The assets list

Response

array<string|int, mixed>

getManagerState

Get the manager state. A collection of registry files and active asset names (per type).

getManagerState() : mixed||string|int
since

4.0.0

Response

array<string|int, mixed>

getRegistry

Get associated registry instance

getRegistry() : \Joomla\CMS\WebAsset\WebAssetRegistry
since

4.0.0

Response

WebAssetRegistry

isAssetActive

Check whether the asset are enabled

isAssetActive( type,  name) : 
throws

UnknownAssetExceptionWhen Asset cannot be found

since

4.0.0

Arguments

type

stringThe asset type, script or style

name

stringThe asset name

Response

bool

lock

Lock the manager to prevent further modifications

lock() : 
since

4.0.0

Response

self

registerAndUsePreset

registerAndUsePreset(\Joomla\CMS\WebAsset\WebAssetItem|string asset,  uri = '',  options,  attributes,  dependencies) : \Joomla\CMS\WebAsset\WebAssetManager

Arguments

asset

WebAssetItem|string

uri = ''

string

options

mixed

attributes

mixed

dependencies

mixed

Response

WebAssetManager

registerAndUseScript

registerAndUseScript(\Joomla\CMS\WebAsset\WebAssetItem|string asset,  uri = '',  options,  attributes,  dependencies) : \Joomla\CMS\WebAsset\WebAssetManager

Arguments

asset

WebAssetItem|string

uri = ''

string

options

mixed

attributes

mixed

dependencies

mixed

Response

WebAssetManager

registerAndUseStyle

registerAndUseStyle(\Joomla\CMS\WebAsset\WebAssetItem|string asset,  uri = '',  options,  attributes,  dependencies) : \Joomla\CMS\WebAsset\WebAssetManager

Arguments

asset

WebAssetItem|string

uri = ''

string

options

mixed

attributes

mixed

dependencies

mixed

Response

WebAssetManager

registerAsset

Register a new asset.

registerAsset( type, \Joomla\CMS\WebAsset\WebAssetItem|string asset,  uri = '', mixed||string|int options = [], mixed||string|int attributes = [], mixed||string|int dependencies = []) : 

Allow to register WebAssetItem instance in the registry, by call registerAsset($type, $assetInstance) Or create an asset on fly (from name and Uri) and register in the registry, by call registerAsset($type, $assetName, $uri, $options ....)

since

4.0.0

throws

InvalidArgumentException

Arguments

type

stringThe asset type, script or style

asset

WebAssetItem|stringThe asset name or instance to register

uri

stringThe URI for the asset

options

array<string|int, mixed>Additional options for the asset

attributes

array<string|int, mixed>Attributes for the asset

dependencies

array<string|int, mixed>Asset dependencies

Response

self

registerPreset

registerPreset(\Joomla\CMS\WebAsset\WebAssetItem|string asset,  uri = '',  options,  attributes,  dependencies) : \Joomla\CMS\WebAsset\WebAssetManager

Arguments

asset

WebAssetItem|string

uri = ''

string

options

mixed

attributes

mixed

dependencies

mixed

Response

WebAssetManager

registerScript

registerScript(\Joomla\CMS\WebAsset\WebAssetItem|string asset,  uri = '',  options,  attributes,  dependencies) : \Joomla\CMS\WebAsset\WebAssetManager

Arguments

asset

WebAssetItem|string

uri = ''

string

options

mixed

attributes

mixed

dependencies

mixed

Response

WebAssetManager

registerStyle

registerStyle(\Joomla\CMS\WebAsset\WebAssetItem|string asset,  uri = '',  options,  attributes,  dependencies) : \Joomla\CMS\WebAsset\WebAssetManager

Arguments

asset

WebAssetItem|string

uri = ''

string

options

mixed

attributes

mixed

dependencies

mixed

Response

WebAssetManager

reset

Clears all collected items.

reset() : 
since

4.1.1

Response

self

useAsset

Enable an asset item to be attached to a Document

useAsset( type,  name) : 
throws

UnknownAssetExceptionWhen Asset cannot be found

InvalidActionExceptionWhen the Manager already attached to a Document

since

4.0.0

Arguments

type

stringThe asset type, script or style

name

stringThe asset name

Response

self

usePreset

usePreset( name) : \Joomla\CMS\WebAsset\WebAssetManager

Arguments

name

mixed

Response

WebAssetManager

usePresetItems

Enable list of assets provided by Preset item.

usePresetItems( name) : 

"Preset" a special kind of asset that hold a list of assets that has to be enabled, same as direct call of useAsset() to each of item in list. Can hold mixed types of assets (script, style, another preset, etc), the type provided after # symbol, after the asset name, example: foo#style, bar#script.

The method call useAsset() internally for each of its dependency, this is important for keeping FIFO order of enabled items. The Preset not a strict asset, and each of its dependency can be safely disabled by use of disableAsset() later.

throws

UnsatisfiedDependencyExceptionWhen Asset dependency cannot be found

since

4.0.0

Arguments

name

stringThe asset name

Response

self

useScript

useScript( name) : \Joomla\CMS\WebAsset\WebAssetManager

Arguments

name

mixed

Response

WebAssetManager

useStyle

useStyle( name) : \Joomla\CMS\WebAsset\WebAssetManager

Arguments

name

mixed

Response

WebAssetManager

Constants

ASSET_STATE_INACTIVE

Mark inactive asset

Value 0
since

4.0.0

Type(s)

int

ASSET_STATE_ACTIVE

Mark active asset. Just enabled, but WITHOUT dependency resolved

Value 1
since

4.0.0

Type(s)

int

ASSET_STATE_DEPENDENCY

Mark active asset that is enabled as dependency to another asset

Value 2
since

4.0.0

Type(s)

int

Properties

registry

The WebAsset Registry instance

since

4.0.0

Type(s)

WebAssetRegistry

activeAssets

A list of active assets (including their dependencies).

Array of Name => State

since

4.0.0

Type(s)

array<string|int, mixed>

locked

Internal marker to check the manager state, to prevent use of the manager after an assets are rendered

since

4.0.0

Type(s)

bool

dependenciesIsActual

Internal marker to keep track when need to recheck dependencies

since

4.0.0

Type(s)

bool