User tests: Successful: Unsuccessful:
As discussed in #23415.
The patch splits WebAssetRegistry
to WebAssetRegistry
and WebAssetManager
.
Additionally it fixes FIFO order of enabled assets and fix #23415.
In general now it like that:
$registry = new WebAssetRegistry;
$registry->add(new WebAssetItem('mother'));
$registry->add(new WebAssetItem('father'));
$registry->add(new WebAssetItem('child1', ['dependencies' => ['mother', 'father']]));
$manager = new WebAssetManager($registry );
$manager->enableAsset('child1'); // Will enable 'child1' asset and all its 'dependencies'
$manager->enableAsset('foo'); // Throw an exception UnknownAsset
$registry->add(new WebAssetItem('foo'));
$manager->enableAsset('foo'); // Will NOT throw an exception UnknownAsset :)
// Check if asset available in registry without an exception
if ($registry->exists('bar'))
{
$manager->enableAsset('bar');
}
In Joomla! context WebAssetRegistry
is a global service, and WebAssetManager
per document instance.
Internaly WebAssetRegistry
load all known assets from joomla.asset.json
.
Work with WebAssetManager:
// Get WebAsset manager instance
$wa = CMSFactory::getDocument()->getWebAssetManager();
// Enable asset
$wa->enableAsset('foo');
// Add new asset on runtime
$wr = $wa->getRegistry();
$wr->add(new WebAssetItem('bar'));
// Add a custom registry file joomla.asset.json
$wr->addRegistryFile($path);
@mbabker @wilsonge please review
yeap
for reference #22435
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
Labels |
Added:
?
|
Status | Pending | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2019-01-08 23:38:22 |
Closed_By | ⇒ | wilsonge |
This looks much better as an API :)