Back to WebAssetRegistry class

Method createAsset

public \Joomla\CMS\WebAsset\WebAssetItem
createAsset
(string $name, string $uri = null, array $options = [], array $attributes = [], array $dependencies = [])
Prepare new Asset instance.
Parameters
  • string $name The asset name
  • 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
  • \Joomla\CMS\WebAsset\WebAssetItem
Since
  • 4.0.0

Method createAsset - Source code

/**
 * Prepare new Asset instance.
 *
 * @param   string  $name          The asset name
 * @param   string  $uri           The URI for the asset
 * @param   array   $options       Additional options for the asset
 * @param   array   $attributes    Attributes for the asset
 * @param   array   $dependencies  Asset dependencies
 *
 * @return  WebAssetItem
 *
 * @since   4.0.0
 */
public function createAsset(string $name, string $uri = null, array $options = [], array $attributes = [], array $dependencies = []) : WebAssetItem
{
    $nameSpace = \array_key_exists('namespace', $options) ? $options['namespace'] : __NAMESPACE__ . '\\AssetItem';
    $className = \array_key_exists('class', $options) ? $options['class'] : null;
    if ($className && class_exists($nameSpace . '\\' . $className)) {
        $className = $nameSpace . '\\' . $className;
        return new $className($name, $uri, $options, $attributes, $dependencies);
    }
    return new WebAssetItem($name, $uri, $options, $attributes, $dependencies);
}