System\Traits\AssetMaker

Source: ~/modules/system/traits/AssetMaker.php

Asset Maker Trait Adds asset based methods to a class

Public properties

public string $assetPath

Specifies a path to the asset directory.

Protected properties

protected array $assets

Collection of assets to display in the layout.

Public methods

public void addCss(string $name, array $attributes=array())

Adds StyleSheet asset to the asset list. Call $this->makeAssets() in a view to output corresponding markup.

Parameters
  • string $name - Specifies a path (URL) to the script.
  • array $attributes - Adds extra HTML attributes to the asset link.

public void addJs(string $name, array $attributes=array())

Adds JavaScript asset to the asset list. Call $this->makeAssets() in a view to output corresponding markup.

Parameters
  • string $name - Specifies a path (URL) to the script.
  • array $attributes - Adds extra HTML attributes to the asset link.

public void addRss(string $name, array $attributes=array())

Adds an RSS link asset to the asset list. Call $this->makeAssets() in a view to output corresponding markup.

Parameters
  • string $name - Specifies a path (URL) to the RSS channel
  • array $attributes - Adds extra HTML attributes to the asset link.

public string combineAssets(array $assets, string $localPath='')

Run the provided assets through the Asset Combiner

Parameters
  • array $assets - Collection of assets
  • string $localPath - Prefix all assets with this path (optional)

public void flushAssets()

Disables the use, and subequent broadcast, of assets. This is useful to call during an AJAX request to speed things up. This method works by specifically targeting the hasAssetsDefined method.

public string getAssetPath(string $fileName, string $assetPath=NULL)

Locates a file based on it's definition. If the file starts with a forward slash, it will be returned in context of the application public path, otherwise it will be returned in context of the asset path.

Parameters
  • string $fileName - File to load.
  • string $assetPath - Explicitly define an asset path.

public array getAssetPaths()

Returns an array of all registered asset paths.

public bool hasAssetsDefined()

Returns true if assets any have been added.

public string makeAssets(string $type=NULL)

Outputs <link> and <script> tags to load assets previously added with addJs and addCss method calls

Parameters
  • string $type - Return an asset collection of a given type (css, rss, js) or null for all.

Protected methods

protected string getAssetEntryBuildPath(array $asset)

Internal helper, attaches a build code to an asset path

Parameters
  • array $asset - Stored asset array

protected string getAssetScheme(string $asset)

Internal helper, get asset scheme

Parameters
  • string $asset - Specifies a path (URL) to the asset.

protected void getLocalPath($relativePath)
Parameters
  • $relativePath

protected void removeDuplicates()

Removes duplicate assets from the entire collection.