PHP Class Themosis\Asset\Asset

Show file Open project: themosis/framework Class Usage Examples

Protected Properties

Property Type Description
$action Themosis\Hook\ActionBuilder
$allowedAreas array Allowed areas.
$area string The default area where to load assets.
$args array WordPress properties of an asset.
$filter Themosis\Hook\FilterBuilder
$html Themosis\Html\HtmlBuilder
$instances array A list of all Asset instances.
$instantiated array A list of enqueued assets.
$key string Asset key name.
$type string Type of the asset.

Public Methods

Method Description
__construct ( string $type, array $args, Themosis\Hook\IHook $action, HtmlBuilder $html, Themosis\Hook\IHook $filter ) Build an Asset instance.
addAttributes ( array $atts ) : Asset Add attributes to the asset opening tag.
getArea ( ) : string Return the asset area.
getArgs ( string $name = '' ) : array | string Return the asset properties. If $name isset, return its value.
getKey ( ) : string Return the asset key.
getType ( ) : string Return the asset type.
inline ( string $data, string $position = 'after' ) : Asset Add inline code before or after the loaded asset.
install ( ) Install the appropriate asset depending of its area.
isQueued ( ) : boolean Tells if an asset is queued or not.
localize ( string $objectName, mixed $data ) : Asset Localize data for the linked asset.
remove ( ) : Asset Remove a declared asset.
to ( string $area ) : Asset Allow the developer to define where to load the asset.

Protected Methods

Method Description
orderInstances ( ) Manipulate the static::$instances variable in order to separate each asset in its area.
parse ( array $args ) : mixed Parse defined asset properties.
parseMixed ( $mixed ) : string | boolean Parse the mixed argument.
parseVersion ( string | boolean | null $version ) : mixed Parse the version number.
register ( Asset $asset ) Register the asset.
registerInline ( Asset $asset ) Register inline code.
registerInstance ( ) Register asset instances.
registerScript ( Asset $asset ) Register a 'script' asset.
registerStyle ( Asset $asset ) Register a 'style' asset.

Method Details

__construct() public method

Build an Asset instance.
public __construct ( string $type, array $args, Themosis\Hook\IHook $action, HtmlBuilder $html, Themosis\Hook\IHook $filter )
$type string
$args array
$action Themosis\Hook\IHook
$html Themosis\Html\HtmlBuilder
$filter Themosis\Hook\IHook

addAttributes() public method

Add attributes to the asset opening tag.
public addAttributes ( array $atts ) : Asset
$atts array The asset attributes to add.
return Asset

getArea() public method

Return the asset area.
public getArea ( ) : string
return string

getArgs() public method

If nothing is defined, return all properties.
public getArgs ( string $name = '' ) : array | string
$name string The argument name.
return array | string

getKey() public method

Return the asset key.
public getKey ( ) : string
return string

getType() public method

Return the asset type.
public getType ( ) : string
return string

inline() public method

Default to "after".
public inline ( string $data, string $position = 'after' ) : Asset
$data string The inline code to output.
$position string Accepts "after" or "before" as values. Note that position is only working for JS assets.
return Asset

install() public method

Install the appropriate asset depending of its area.
public install ( )

isQueued() public method

Tells if an asset is queued or not.
public isQueued ( ) : boolean
return boolean

localize() public method

Output JS object right before the script output.
public localize ( string $objectName, mixed $data ) : Asset
$objectName string The name of the JS variable that will hold the data.
$data mixed Any data to attach to the JS variable: string, boolean, object, array, ...
return Asset

orderInstances() protected method

Manipulate the static::$instances variable in order to separate each asset in its area.
protected orderInstances ( )

parse() protected method

Parse defined asset properties.
protected parse ( array $args ) : mixed
$args array The asset properties.
return mixed

parseMixed() protected method

Parse the mixed argument.
protected parseMixed ( $mixed ) : string | boolean
$mixed
return string | boolean

parseVersion() protected method

Parse the version number.
protected parseVersion ( string | boolean | null $version ) : mixed
$version string | boolean | null
return mixed

register() protected method

Register the asset.
protected register ( Asset $asset )
$asset Asset

registerInline() protected method

Register inline code.
protected registerInline ( Asset $asset )
$asset Asset

registerInstance() protected method

Register asset instances.
protected registerInstance ( )

registerScript() protected method

Register a 'script' asset.
protected registerScript ( Asset $asset )
$asset Asset

registerStyle() protected method

Register a 'style' asset.
protected registerStyle ( Asset $asset )
$asset Asset

remove() public method

Remove a declared asset.
public remove ( ) : Asset
return Asset

to() public method

Only 'admin', 'login' and 'customizer' are accepted. If none of those values are used, simply keep the default front-end area.
public to ( string $area ) : Asset
$area string Specify where to load the asset: 'admin', 'login' or 'customizer'.
return Asset

Property Details

$action protected property

protected ActionBuilder,Themosis\Hook $action
return Themosis\Hook\ActionBuilder

$allowedAreas protected property

Allowed areas.
protected array $allowedAreas
return array

$area protected property

The default area where to load assets.
protected string $area
return string

$args protected property

WordPress properties of an asset.
protected array $args
return array

$filter protected property

protected FilterBuilder,Themosis\Hook $filter
return Themosis\Hook\FilterBuilder

$html protected property

protected HtmlBuilder,Themosis\Html $html
return Themosis\Html\HtmlBuilder

$instances protected static property

A list of all Asset instances.
protected static array $instances
return array

$instantiated protected static property

A list of enqueued assets.
protected static array $instantiated
return array

$key protected property

Asset key name.
protected string $key
return string

$type protected property

Type of the asset.
protected string $type
return string