AssetMaker Trait Adds asset based methods to a class

Public Properties

public string $assetPath

assetPath specifies the relative path to the asset directory.

public string $assetUrlPath

assetUrlPath specifies the public 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.

protected string $assetDefaults

assetDefaults is the default attributes for assets.

Public Methods

public addCss()

public addCss($name, $attributes = []): void

addCss includes a StyleSheet asset to the asset list

public addCssBundle()

public addCssBundle($name, $attributes = []): void

addCssBundle includes a CSS asset to the bundled combiner pipeline

public addJs()

public addJs($name, $attributes = []): void

addJs includes a JavaScript asset to the asset list

public addJsBundle()

public addJsBundle($name, $attributes = []): void

addJsBundle includes a JS asset to the bundled combiner pipeline

public addRss()

public addRss($name, $attributes = []): void

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

public combineAssets()

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

combineAssets runs asset paths through the Asset Combiner

public flushAssets()

public flushAssets(): void 

flushAssets disables the use, and subsequent 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 getAssetPath()

public getAssetPath(
    string $fileName,
    string $assetPath = null
): string 

getAssetPath 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.

public getAssetPaths()

public getAssetPaths(): array 

getAssetPaths returns an array of all registered asset paths.

public hasAssetsDefined()

public hasAssetsDefined(): bool 

hasAssetsDefined returns true if assets any have been added

public makeAssets()

public makeAssets(string $type = null): string 

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

Protected Methods

protected combineBundledAssets()

protected combineBundledAssets($type): array 

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

protected getAssetEntryBuildPath()

protected getAssetEntryBuildPath(array $asset): string 

Internal helper, attaches a build code to an asset path

protected getAssetScheme()

protected getAssetScheme($asset): string 

getAssetScheme is an internal helper to get the asset scheme.

protected getLocalPath()

protected getLocalPath($relativePath): string 

getLocalPath converts a relative path to a local path

protected processAssetAttributes()

protected processAssetAttributes($attributes): void

protected removeDuplicateAssets()

protected removeDuplicateAssets(): void

removeDuplicateAssets removes duplicate and global assets from the entire collection

protected renderAssetAttributes()

protected renderAssetAttributes($type, $asset): string 

renderAssetAttributes takes an asset definition and returns the necessary HTML output