WebAssetManager

Implements WebAssetManagerInterface

Web Asset Manager class

since

4.0.0

package

Application

Methods

__call

Adds support for magic method calls

__call(string method, array arguments) : mixed
throws

\BadMethodCallException

since

4.0.0

Arguments

method

stringA method name

arguments

arrayArguments for a method

Response

mixed

__construct

Class constructor

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

4.0.0

Arguments

registry

\Joomla\CMS\WebAsset\WebAssetRegistryThe WebAsset Registry instance

Response

mixed

addInline

Add a new inline content asset.

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

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

\Joomla\CMS\WebAsset\WebAssetItem|stringThe content to of inline asset

options

arrayAdditional options for the asset

attributes

arrayAttributes for the asset

dependencies

arrayAsset dependencies

Response

self

addInlineScript

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

Arguments

content

\Joomla\CMS\WebAsset\WebAssetItem|string

options

mixed

attributes

mixed

dependencies

mixed

Response

\Joomla\CMS\WebAsset\WebAssetManager

addInlineStyle

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

Arguments

content

\Joomla\CMS\WebAsset\WebAssetItem|string

options

mixed

attributes

mixed

dependencies

mixed

Response

\Joomla\CMS\WebAsset\WebAssetManager

assetExists

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

assetExists(string type, string name) : bool
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(string type) : \Joomla\CMS\WebAsset\WebAssetItem[]
since

4.0.0

Arguments

type

stringThe asset type, script or style

Response

\Joomla\CMS\WebAsset\WebAssetItem[]

disableAsset

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

disableAsset(string type, string name) : self
throws

\Joomla\CMS\WebAsset\Exception\UnknownAssetExceptionWhen Asset cannot be found

\Joomla\CMS\WebAsset\Exception\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(mixed name) : \Joomla\CMS\WebAsset\WebAssetManager

Arguments

name

mixed

Response

\Joomla\CMS\WebAsset\WebAssetManager

disablePresetItems

Deactivate list of assets provided by Preset item.

disablePresetItems(string name) : self
throws

\Joomla\CMS\WebAsset\Exception\UnsatisfiedDependencyExceptionWhen Asset dependency cannot be found

since

4.0.0

Arguments

name

stringThe asset name

Response

self

disableScript

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

Arguments

name

mixed

Response

\Joomla\CMS\WebAsset\WebAssetManager

disableStyle

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

Arguments

name

mixed

Response

\Joomla\CMS\WebAsset\WebAssetManager

enableDependencies

Update Dependencies state for all active Assets or only for given

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

4.0.0

Arguments

type

stringThe asset type, script or style

asset

\Joomla\CMS\WebAsset\WebAssetItemThe asset instance to which need to enable dependencies

Response

self

filterOutInlineAssets

Helper method to filter an inline assets

filterOutInlineAssets(\Joomla\CMS\WebAsset\WebAssetItem[] &assets) : \Joomla\CMS\WebAsset\WebAssetItem[]
since

4.0.0

Arguments

assets

\Joomla\CMS\WebAsset\WebAssetItem[]Reference to a full list of active assets

Response

\Joomla\CMS\WebAsset\WebAssetItem[]Array of inline assets

getAsset

Helper method to get the asset from the registry.

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

\Joomla\CMS\WebAsset\Exception\UnknownAssetExceptionWhen Asset cannot be found

since

4.0.0

Arguments

type

stringAsset type, script or style

name

stringAsset name

Response

\Joomla\CMS\WebAsset\WebAssetItemInterface

getAssets

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

getAssets(string type, bool sort = false) : \Joomla\CMS\WebAsset\WebAssetItem[]
throws

\Joomla\CMS\WebAsset\Exception\UnknownAssetExceptionWhen Asset cannot be found

\Joomla\CMS\WebAsset\Exception\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

\Joomla\CMS\WebAsset\WebAssetItem[]

getAssetState

Get a state for the Asset

getAssetState(string type, string name) : int
throws

\Joomla\CMS\WebAsset\Exception\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[] assets) : array
since

4.0.0

Arguments

assets

\Joomla\CMS\WebAsset\WebAssetItem[]Asset instances

Response

array

getDependenciesForAsset

Return dependencies for Asset as array of WebAssetItem objects

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

\Joomla\CMS\WebAsset\Exception\UnsatisfiedDependencyExceptionWhen Dependency cannot be found

since

4.0.0

Arguments

type

stringThe asset type, script or style

asset

\Joomla\CMS\WebAsset\WebAssetItemAsset instance

recursively

boolWhether to search for dependency recursively

recursionType

stringThe type of initial item to prevent loop

recursionRoot

\Joomla\CMS\WebAsset\WebAssetItemInitial item to prevent loop

Response

array

getInlineRelation

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

getInlineRelation(\Joomla\CMS\WebAsset\WebAssetItem[] assets) : array

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

\Joomla\CMS\WebAsset\WebAssetItem[]The assets list

Response

array

getManagerState

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

getManagerState() : array
since

4.0.0

Response

array

getRegistry

Get associated registry instance

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

4.0.0

Response

\Joomla\CMS\WebAsset\WebAssetRegistry

isAssetActive

Check whether the asset are enabled

isAssetActive(string type, string name) : bool
throws

\Joomla\CMS\WebAsset\Exception\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() : self
since

4.0.0

Response

self

registerAndUsePreset

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

Arguments

asset

\Joomla\CMS\WebAsset\WebAssetItem|string

uri = ''

string

options

mixed

attributes

mixed

dependencies

mixed

Response

\Joomla\CMS\WebAsset\WebAssetManager

registerAndUseScript

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

Arguments

asset

\Joomla\CMS\WebAsset\WebAssetItem|string

uri = ''

string

options

mixed

attributes

mixed

dependencies

mixed

Response

\Joomla\CMS\WebAsset\WebAssetManager

registerAndUseStyle

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

Arguments

asset

\Joomla\CMS\WebAsset\WebAssetItem|string

uri = ''

string

options

mixed

attributes

mixed

dependencies

mixed

Response

\Joomla\CMS\WebAsset\WebAssetManager

registerAsset

Register a new asset.

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

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

\Joomla\CMS\WebAsset\WebAssetItem|stringThe asset name or instance to register

uri

stringThe URI for the asset

options

arrayAdditional options for the asset

attributes

arrayAttributes for the asset

dependencies

arrayAsset dependencies

Response

self

registerPreset

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

Arguments

asset

\Joomla\CMS\WebAsset\WebAssetItem|string

uri = ''

string

options

mixed

attributes

mixed

dependencies

mixed

Response

\Joomla\CMS\WebAsset\WebAssetManager

registerScript

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

Arguments

asset

\Joomla\CMS\WebAsset\WebAssetItem|string

uri = ''

string

options

mixed

attributes

mixed

dependencies

mixed

Response

\Joomla\CMS\WebAsset\WebAssetManager

registerStyle

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

Arguments

asset

\Joomla\CMS\WebAsset\WebAssetItem|string

uri = ''

string

options

mixed

attributes

mixed

dependencies

mixed

Response

\Joomla\CMS\WebAsset\WebAssetManager

reset

Clears all collected items.

reset() : self
since

4.1.1

Response

self

useAsset

Enable an asset item to be attached to a Document

useAsset(string type, string name) : self
throws

\Joomla\CMS\WebAsset\Exception\UnknownAssetExceptionWhen Asset cannot be found

\Joomla\CMS\WebAsset\Exception\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(mixed name) : \Joomla\CMS\WebAsset\WebAssetManager

Arguments

name

mixed

Response

\Joomla\CMS\WebAsset\WebAssetManager

usePresetItems

Enable list of assets provided by Preset item.

usePresetItems(string name) : self

"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

\Joomla\CMS\WebAsset\Exception\UnsatisfiedDependencyExceptionWhen Asset dependency cannot be found

since

4.0.0

Arguments

name

stringThe asset name

Response

self

useScript

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

Arguments

name

mixed

Response

\Joomla\CMS\WebAsset\WebAssetManager

useStyle

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

Arguments

name

mixed

Response

\Joomla\CMS\WebAsset\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

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