AssetMaker
Asset Maker Trait
Adds asset based methods to a class
trait System\Traits\AssetMaker
Properties
public $assetPath : string
Specifies a path to the asset directory.
protected
$assets
:
array
= {"js":[],"css":[],"rss":[]}
Collection of assets to display in the layout.
Methods
public
addCss (array | string $name, array $attributes = []
)
: void
Adds StyleSheet asset to the asset list. Call $this->makeAssets() in a view to output corresponding markup.
Property | Type | Description |
---|---|---|
$name | array | string |
array | string
Specifies a path (URL) or an array of paths to the stylesheet(s). |
$attributes | array |
array
Adds extra HTML attributes to the asset link. |
public
addJs (array | string $name, array $attributes = []
)
: void
Adds JavaScript asset to the asset list. Call $this->makeAssets() in a view to output corresponding markup.
Property | Type | Description |
---|---|---|
$name | array | string |
array | string
Specifies a path (URL) or an array of paths to the script(s). |
$attributes | array |
array
Adds extra HTML attributes to the asset link. |
public
addRss (string $name, array $attributes = []
)
: void
Adds an RSS link asset to the asset list. Call $this->makeAssets() in a view to output corresponding markup.
Property | Type | Description |
---|---|---|
$name | string |
string
Specifies a path (URL) to the RSS channel |
$attributes | array |
array
Adds extra HTML attributes to the asset link. |
public
combineAssets (array $assets, string $localPath = ""
)
: string
Run the provided assets through the Asset Combiner
Property | Type | Description |
---|---|---|
$assets | array |
array
Collection of assets |
$localPath | string |
string
Prefix all assets with this path (optional) |
public flushAssets () : void
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
getAssetPath (string $fileName, string $assetPath = null
)
: string
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.
Property | Type | Description |
---|---|---|
$fileName | string |
string
File to load. |
$assetPath | string |
string
Explicitly define an asset path. |
Relative path to the asset file.
public getAssetPaths () : array
Returns an array of all registered asset paths.
public hasAssetsDefined () : bool
Returns true if assets any have been added.
public
makeAssets ($type = null
)
: string | null
Outputs <link>
and <script>
tags to load assets previously added
with addJs, addCss, & addRss method calls depending on the provided $type
Property | Type | Description |
---|---|---|
$type | mixed |
mixed
|
protected addAsset (string $type, string $path, array $attributes)
Adds the provided asset to the internal asset collections
Property | Type | Description |
---|---|---|
$type | string |
string
The type of the asset: 'js' || 'css' || 'rss' |
$path | string |
string
The path to the asset |
$attributes | array |
array
The attributes for the asset |
protected getAssetEntryBuildPath (array $asset) : string
Internal helper, attaches a build code to an asset path
Property | Type | Description |
---|---|---|
$asset | array |
array
Stored asset array |
protected getAssetScheme (string $asset) : string
Internal helper, get asset scheme
Property | Type | Description |
---|---|---|
$asset | string |
string
Specifies a path (URL) to the asset. |
protected getLocalPath (string | null $relativePath)
Property | Type | Description |
---|---|---|
$relativePath | string | null |
string | null
|
protected removeDuplicates () : void
Removes duplicate assets from the entire collection.