System\Traits\AssetMaker

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.

protected array $assetBundles

Collection of combined and prioritized assets.

Public methods

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

addCss includes a StyleSheet asset to the asset list

Parameters
  • $name
  • $attributes

public void addCssBundle($name, $attributes=array())

addCssBundle includes a CSS asset to the bundled combiner stream

Parameters
  • $name
  • $attributes

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

addJs includes a JavaScript asset to the asset list

Parameters
  • $name
  • $attributes

public void addJsBundle($name, $attributes=array())

addJsBundle includes a JS asset to the bundled combiner stream

Parameters
  • $name
  • $attributes

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

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

Parameters
  • $name
  • $attributes

public void combineAssets($assets, $localPath='')

combineAssets runs asset paths through the Asset Combiner

Parameters
  • $assets
  • $localPath

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 void hasAssetsDefined()

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 void combineBundledAssets($type)

combineBundledAssets spins over every bundle definition and combines them to an asset

Parameters
  • $type

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)

getLocalPath converts a relative path to a local path

Parameters
  • $relativePath

protected void removeDuplicates()

Removes duplicate assets from the entire collection.

protected void renderAssetAttributes($type, $asset)

renderAssetAttributes takes an asset definition and returns the necessary HTML output

Parameters
  • $type
  • $asset