Asset Factory
Table of contents
AssetFactory
Instead of creating instances by hand, it’s sometimes easier to use configuration via array or file to manage your specific assets.
Note: The
AssetFactory
is replaced step by step via Loaders. Methods are set to @deprecated
which have been moved to a Loader.
AssetFactory::create()
To create a single Asset from an array, you can do following:
<?php
use Inpsyde\Assets\AssetFactory;
use Inpsyde\Assets\Asset;
use Inpsyde\Assets\Style;
use Inpsyde\Assets\ScriptModule;
/** @var Style $asset */
$asset = AssetFactory::create(
[
'handle' => 'foo',
'url' => 'www.example.com/assets/style.css',
'location' => Asset::FRONTEND,
'type' => Style::class
],
);
/** @var ScriptModule $module */
$module = AssetFactory::create(
[
'handle' => '@my-plugin/dashboard',
'url' => 'www.example.com/assets/dashboard.js',
'location' => Asset::FRONTEND,
'type' => ScriptModule::class,
'dependencies' => ['@wordpress/interactivity', '@wordpress/element'],
'version' => '1.0.0'
]
);