Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.0] WebAsset: split WebAssetRegistry to Registry and Manager #23463

Merged
merged 17 commits into from
Jan 8, 2019

Conversation

Fedik
Copy link
Member

@Fedik Fedik commented Jan 6, 2019

Summary of Changes

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

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

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

Documentation Changes Required

yeap

for reference #22435

@wilsonge wilsonge merged commit 593e41d into joomla:4.0-dev Jan 8, 2019
@wilsonge
Copy link
Contributor

wilsonge commented Jan 8, 2019

This looks much better as an API :)

@wilsonge wilsonge added this to the Joomla 4.0 milestone Jan 8, 2019
@Fedik Fedik deleted the asset-manager-split branch January 9, 2019 09:02
@Fedik Fedik mentioned this pull request Aug 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants