WebAssetRegistry

Implements WebAssetRegistryInterface, DispatcherAwareInterface

Web Asset Registry class

since

4.0.0

package

Joomla CMS

Methods

__construct

Registry constructor

__construct() : 
since

4.0.0

Response

mixed

add

Add Asset to registry of known assets

add( type, \Joomla\CMS\WebAsset\WebAssetItemInterface asset) : 
since

4.0.0

Arguments

type

stringAsset type, script or style

asset

WebAssetItemInterfaceAsset instance

Response

self

addExtensionRegistryFile

Helper method to register new file with Extension Asset(s) info

addExtensionRegistryFile( name) : 
since

4.0.0

Arguments

name

stringA full extension name, actually a name in the /media folder, eg: com_example, plg_system_example etc.

Response

self

addRegistryFile

Register new file with Asset(s) info

addRegistryFile( path) : 
since

4.0.0

Arguments

path

stringRelative path

Response

self

addTemplateRegistryFile

Helper method to register new file with Template Asset(s) info

addTemplateRegistryFile( template,  client) : 
since

4.0.0

Arguments

template

stringThe template name

client

intThe application client id

Response

self

createAsset

Prepare new Asset instance.

createAsset( name,  uri = null, mixed||string|int options = [], mixed||string|int attributes = [], mixed||string|int dependencies = []) : \Joomla\CMS\WebAsset\WebAssetItem
since

4.0.0

Arguments

name

stringThe asset name

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

WebAssetItem

dispatchAssetChanged

Dispatch an event to notify listeners about asset changes: new, remove, override Events:

  • onWebAssetRegistryChangedAssetNew When new asset added to the registry
  • onWebAssetRegistryChangedAssetOverride When the asset overridden
  • onWebAssetRegistryChangedAssetRemove When new asset was removed from the registry
dispatchAssetChanged( type, \Joomla\CMS\WebAsset\WebAssetItemInterface asset,  change) : 
since

4.0.0

Arguments

type

stringAsset type, script or style

asset

WebAssetItemInterfaceAsset instance

change

stringA type of change: new, remove, override

Response

void

exists

Check whether the asset exists in the registry.

exists( type,  name) : 
since

4.0.0

Arguments

type

stringAsset type, script or style

name

stringAsset name

Response

bool

get

Get an existing Asset from a registry, by asset name.

get( type,  name) : \Joomla\CMS\WebAsset\WebAssetItem
throws

UnknownAssetExceptionWhen Asset cannot be found

since

4.0.0

Arguments

type

stringAsset type, script or style

name

stringAsset name

Response

WebAssetItem

getRegistryFiles

Get a list of the registry files

getRegistryFiles() : mixed||string|int
since

4.0.0

Response

array<string|int, mixed>

parseRegistryFile

Parse registry file

parseRegistryFile( path) : 
throws

RuntimeExceptionIf file is empty or invalid

since

4.0.0

Arguments

path

stringRelative path to the data file

Response

void

parseRegistryFiles

Parse registered files

parseRegistryFiles() : 
since

4.0.0

Response

void

remove

Remove Asset from registry.

remove( type,  name) : 
since

4.0.0

Arguments

type

stringAsset type, script or style

name

stringAsset name

Response

self

Properties

dataFilesNew

Files with Asset info. File path should be relative.

example

of registry file:

{ "title" : "Example", "name" : "com_example", "author": "Joomla! CMS", "assets": [ { "name": "library1", "version": "3.5.0", "type": "script", "uri": "com_example/library1.min.js" }, { "name": "library2", "version": "3.5.0", "type": "script", "uri": "com_example/library2.min.js", "dependencies": [ "core", "library1" ], "attribute": { "attr-name": "attr value" "defer": true } }, { "name": "library1", "version": "3.5.0", "type": "style", "uri": "com_example/library1.min.css" "attribute": { "media": "all" } }, { "name": "library1", "type": "preset", "dependencies": { "library1#style", "library1#script" } }, ] }

since

4.0.0

Type(s)

array<string|int, mixed>

dataFilesParsed

List of parsed files

since

4.0.0

Type(s)

array<string|int, mixed>

assets

Registry of available Assets

since

4.0.0

Type(s)

array<string|int, mixed>