WebAssetRegistry

Implements \Joomla\CMS\WebAsset\WebAssetRegistryInterface, \Joomla\Event\DispatcherAwareInterface

Web Asset Registry class

since

4.0.0

Methods

__construct

Registry constructor

__construct() 
since

4.0.0

add

Add Asset to registry of known assets

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

4.0.0

Arguments

$type

stringAsset type, script or style

$asset

\Joomla\CMS\WebAsset\WebAssetItemInterfaceAsset instance

Response

self

addExtensionRegistryFile

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

addExtensionRegistryFile(string $name) : self
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(string $path) : self
since

4.0.0

Arguments

$path

stringRelative path

Response

self

addTemplateRegistryFile

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

addTemplateRegistryFile(string $template, integer $client) : self
since

4.0.0

Arguments

$template

stringThe template name

$client

integerThe application client id

Response

self

createAsset

Prepare new Asset instance.

createAsset(string $name, string $uri = null, array $options = array(), array $attributes = array(), array $dependencies = array()) : \Joomla\CMS\WebAsset\WebAssetItem
since

4.0.0

Arguments

$name

stringThe asset name

$uri

stringThe URI for the asset

$options

arrayAdditional options for the asset

$attributes

arrayAttributes for the asset

$dependencies

arrayAsset dependencies

Response

\Joomla\CMS\WebAsset\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(string $type, \Joomla\CMS\WebAsset\WebAssetItemInterface $asset, string $change) : void
since

4.0.0

Arguments

$type

stringAsset type, script or style

$asset

\Joomla\CMS\WebAsset\WebAssetItemInterfaceAsset instance

$change

stringA type of change: new, remove, override

exists

Check whether the asset exists in the registry.

exists(string $type, string $name) : boolean
since

4.0.0

Arguments

$type

stringAsset type, script or style

$name

stringAsset name

Response

boolean

get

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

get(string $type, string $name) : \Joomla\CMS\WebAsset\WebAssetItem
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\WebAssetItem

getRegistryFiles

Get a list of the registry files

getRegistryFiles() : array
since

4.0.0

Response

array

parseRegistryFile

Parse registry file

parseRegistryFile(string $path) : void
throws

\RuntimeExceptionIf file is empty or invalid

since

4.0.0

Arguments

$path

stringRelative path to the data file

parseRegistryFiles

Parse registered files

parseRegistryFiles() : void
since

4.0.0

remove

Remove Asset from registry.

remove(string $type, string $name) : self
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

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

dataFilesParsed

List of parsed files

since

4.0.0

Type(s)

array

assets

Registry of available Assets

since

4.0.0

Type(s)

array