Back to Joomla project (class list)

Class WebAssetManager - list of methods

Web Asset Manager class

Extends

Package: Joomla\CMS\WebAsset
Copyright: (C) 2019 Open Source Matters, Inc.
License: GNU General Public License version 2 or later; see LICENSE.txt
Located at: Joomla/WebAsset/WebAssetManager.php
Project: Joomla

Method Summary

public
(\Joomla\CMS\WebAsset\WebAssetRegistry $registry)

Class constructor
Parameters
  • \Joomla\CMS\WebAsset\WebAssetRegistry $registry The WebAsset Registry instance
Since
  • 4.0.0
Show source code of this method: __construct Source Code

public \Joomla\CMS\WebAsset\WebAssetRegistry
()

Get associated registry instance
Returns
  • \Joomla\CMS\WebAsset\WebAssetRegistry
Since
  • 4.0.0
Show source code of this method: getRegistry Source Code

public self
()

Clears all collected items.
Returns
  • self
Since
  • 4.1.1
Show source code of this method: reset Source Code

public mixed
(mixed $method, mixed $arguments)

Adds support for magic method calls
Parameters
  • string $method A method name
  • array $arguments Arguments for a method
Returns
  • mixed
Since
  • 4.0.0
-
  • \BadMethodCallException
Show source code of this method: __call Source Code

public self
(string $type, string $name)

Enable an asset item to be attached to a Document
Parameters
  • string $type The asset type, script or style
  • string $name The asset name
Returns
  • self
Since
  • 4.0.0
-
  • \Joomla\CMS\WebAsset\Exception\UnknownAssetException When Asset cannot be found
  • \Joomla\CMS\WebAsset\Exception\InvalidActionException When the Manager already attached to a Document
Show source code of this method: useAsset Source Code

public self
(string $type, string $name)

Deactivate an asset item, so it will not be attached to a Document
Parameters
  • string $type The asset type, script or style
  • string $name The asset name
Returns
  • self
Since
  • 4.0.0
-
  • \Joomla\CMS\WebAsset\Exception\UnknownAssetException When Asset cannot be found
  • \Joomla\CMS\WebAsset\Exception\InvalidActionException When the Manager already attached to a Document
Show source code of this method: disableAsset Source Code

protected self
(mixed $name)

Enable list of assets provided by Preset item.
Parameters
  • string $name The asset name
Returns
  • self
Since
  • 4.0.0
-
  • \Joomla\CMS\WebAsset\Exception\UnsatisfiedDependencyException When Asset dependency cannot be found
Show source code of this method: usePresetItems Source Code

protected self
(mixed $name)

Deactivate list of assets provided by Preset item.
Parameters
  • string $name The asset name
Returns
  • self
Since
  • 4.0.0
-
  • \Joomla\CMS\WebAsset\Exception\UnsatisfiedDependencyException When Asset dependency cannot be found
Show source code of this method: disablePresetItems Source Code

public int
(string $type, string $name)

Get a state for the Asset
Parameters
  • string $type The asset type, script or style
  • string $name The asset name
Returns
  • int
Since
  • 4.0.0
-
  • \Joomla\CMS\WebAsset\Exception\UnknownAssetException When Asset cannot be found
Show source code of this method: getAssetState Source Code

public bool
(string $type, string $name)

Check whether the asset are enabled
Parameters
  • string $type The asset type, script or style
  • string $name The asset name
Returns
  • bool
Since
  • 4.0.0
-
  • \Joomla\CMS\WebAsset\Exception\UnknownAssetException When Asset cannot be found
Show source code of this method: isAssetActive Source Code

public bool
(string $type, string $name)

Helper method to check whether the asset exists in the registry.
Parameters
  • string $type Asset type, script or style
  • string $name Asset name
Returns
  • bool
Since
  • 4.0.0
Show source code of this method: assetExists Source Code

public self
(string $type, mixed $asset, string $uri = '', array $options = [], array $attributes = [], array $dependencies = [])

Register a new asset.
Parameters
  • string $type The asset type, script or style
  • \Joomla\CMS\WebAsset\WebAssetItem|string $asset The asset name or instance to register
  • string $uri The URI for the asset
  • array $options Additional options for the asset
  • array $attributes Attributes for the asset
  • array $dependencies Asset dependencies
Returns
  • self
Since
  • 4.0.0
-
  • \InvalidArgumentException
Show source code of this method: registerAsset Source Code

public \Joomla\CMS\WebAsset\WebAssetItemInterface
(string $type, string $name)

Helper method to get the asset from the registry.
Parameters
  • string $type Asset type, script or style
  • string $name Asset name
Returns
  • \Joomla\CMS\WebAsset\WebAssetItemInterface
Since
  • 4.0.0
-
  • \Joomla\CMS\WebAsset\Exception\UnknownAssetException When Asset cannot be found
Show source code of this method: getAsset Source Code

public \Joomla\CMS\WebAsset\WebAssetItem[]
(string $type, bool $sort = false)

Get all active assets, optionally sort them to follow the dependency Graph
Parameters
  • string $type The asset type, script or style
  • bool $sort Whether need to sort the assets to follow the dependency Graph
Returns
  • \Joomla\CMS\WebAsset\WebAssetItem[]
Since
  • 4.0.0
-
  • \Joomla\CMS\WebAsset\Exception\UnknownAssetException When Asset cannot be found
  • \Joomla\CMS\WebAsset\Exception\UnsatisfiedDependencyException When Dependency cannot be found
Show source code of this method: getAssets Source Code

public array
(array $assets)

Helper method to calculate inline to non inline relation (before/after positions).
Parameters
  • \Joomla\CMS\WebAsset\WebAssetItem[] $assets The assets list
Returns
  • array
Since
  • 4.0.0
Show source code of this method: getInlineRelation Source Code

public \Joomla\CMS\WebAsset\WebAssetItem[]
(array &$assets)

Helper method to filter an inline assets
Parameters
  • \Joomla\CMS\WebAsset\WebAssetItem[] $assets Reference to a full list of active assets
Returns
  • \Joomla\CMS\WebAsset\WebAssetItem[] Array of inline assets
Since
  • 4.0.0
Show source code of this method: filterOutInlineAssets Source Code

public self
(string $type, mixed $content, array $options = [], array $attributes = [], array $dependencies = [])

Add a new inline content asset.
Parameters
  • string $type The asset type, script or style
  • \Joomla\CMS\WebAsset\WebAssetItem|string $content The content to of inline asset
  • array $options Additional options for the asset
  • array $attributes Attributes for the asset
  • array $dependencies Asset dependencies
Returns
  • self
Since
  • 4.0.0
-
  • \InvalidArgumentException
Show source code of this method: addInline Source Code

public self
()

Lock the manager to prevent further modifications
Returns
  • self
Since
  • 4.0.0
Show source code of this method: lock Source Code

public array
()

Get the manager state. A collection of registry files and active asset names (per type).
Returns
  • array
Since
  • 4.0.0
Show source code of this method: getManagerState Source Code

protected self
(string $type = null, \Joomla\CMS\WebAsset\WebAssetItem $asset = null)

Update Dependencies state for all active Assets or only for given
Parameters
  • string $type The asset type, script or style
  • \Joomla\CMS\WebAsset\WebAssetItem $asset The asset instance to which need to enable dependencies
Returns
  • self
Since
  • 4.0.0
Show source code of this method: enableDependencies Source Code

protected \Joomla\CMS\WebAsset\WebAssetItem[]
(mixed $type)

Calculate weight of active Assets, by its Dependencies
Parameters
  • string $type The asset type, script or style
Returns
  • \Joomla\CMS\WebAsset\WebAssetItem[]
Since
  • 4.0.0
Show source code of this method: calculateOrderOfActiveAssets Source Code

protected array
(array $assets)

Build Graph of Outgoing and Incoming connections for given assets.
Parameters
  • \Joomla\CMS\WebAsset\WebAssetItem[] $assets Asset instances
Returns
  • array
Since
  • 4.0.0
Show source code of this method: getConnectionsGraph Source Code

protected array
(string $type, \Joomla\CMS\WebAsset\WebAssetItem $asset, mixed $recursively = false, string $recursionType = null, \Joomla\CMS\WebAsset\WebAssetItem $recursionRoot = null)

Return dependencies for Asset as array of WebAssetItem objects
Parameters
  • string $type The asset type, script or style
  • \Joomla\CMS\WebAsset\WebAssetItem $asset Asset instance
  • bool $recursively Whether to search for dependency recursively
  • string $recursionType The type of initial item to prevent loop
  • \Joomla\CMS\WebAsset\WebAssetItem $recursionRoot Initial item to prevent loop
Returns
  • array
Since
  • 4.0.0
-
  • \Joomla\CMS\WebAsset\Exception\UnsatisfiedDependencyException When Dependency cannot be found
Show source code of this method: getDependenciesForAsset Source Code

Properties Summary

protected \Joomla\CMS\WebAsset\WebAssetRegistry
$registry
The WebAsset Registry instance
Since
  • 4.0.0
protected array
$activeAssets
A list of active assets (including their dependencies).
Since
  • 4.0.0
protected bool
$locked
Internal marker to check the manager state, to prevent use of the manager after an assets are rendered
Since
  • 4.0.0
protected bool
$dependenciesIsActual
Internal marker to keep track when need to recheck dependencies
Since
  • 4.0.0

Constants Summary

public int
$ASSET_STATE_INACTIVE
Mark inactive asset
Since
  • 4.0.0
public int
$ASSET_STATE_ACTIVE
Mark active asset. Just enabled, but WITHOUT dependency resolved
Since
  • 4.0.0
public int
$ASSET_STATE_DEPENDENCY
Mark active asset that is enabled as dependency to another asset
Since
  • 4.0.0

Tags Summary

public \Joomla\CMS\WebAsset\WebAssetManager
registerStyle (\Joomla\CMS\WebAsset\WebAssetItem|string $asset, string $uri = '', mixed $options, mixed $attributes, mixed $dependencies)
public \Joomla\CMS\WebAsset\WebAssetManager
registerAndUseStyle (\Joomla\CMS\WebAsset\WebAssetItem|string $asset, string $uri = '', mixed $options, mixed $attributes, mixed $dependencies)
public \Joomla\CMS\WebAsset\WebAssetManager
useStyle (mixed $name)
public \Joomla\CMS\WebAsset\WebAssetManager
disableStyle (mixed $name)
public \Joomla\CMS\WebAsset\WebAssetManager
addInlineStyle (\Joomla\CMS\WebAsset\WebAssetItem|string $content, mixed $options, mixed $attributes, mixed $dependencies)
public \Joomla\CMS\WebAsset\WebAssetManager
registerScript (\Joomla\CMS\WebAsset\WebAssetItem|string $asset, string $uri = '', mixed $options, mixed $attributes, mixed $dependencies)
public \Joomla\CMS\WebAsset\WebAssetManager
registerAndUseScript (\Joomla\CMS\WebAsset\WebAssetItem|string $asset, string $uri = '', mixed $options, mixed $attributes, mixed $dependencies)
public \Joomla\CMS\WebAsset\WebAssetManager
useScript (mixed $name)
public \Joomla\CMS\WebAsset\WebAssetManager
disableScript (mixed $name)
public \Joomla\CMS\WebAsset\WebAssetManager
addInlineScript (\Joomla\CMS\WebAsset\WebAssetItem|string $content, mixed $options, mixed $attributes, mixed $dependencies)
public \Joomla\CMS\WebAsset\WebAssetManager
registerPreset (\Joomla\CMS\WebAsset\WebAssetItem|string $asset, string $uri = '', mixed $options, mixed $attributes, mixed $dependencies)
public \Joomla\CMS\WebAsset\WebAssetManager
registerAndUsePreset (\Joomla\CMS\WebAsset\WebAssetItem|string $asset, string $uri = '', mixed $options, mixed $attributes, mixed $dependencies)
public \Joomla\CMS\WebAsset\WebAssetManager
usePreset (mixed $name)
public \Joomla\CMS\WebAsset\WebAssetManager
disablePreset (mixed $name)
Since
4.0.0