protected array
getDependenciesForAsset
(string $type, \Joomla\CMS\WebAsset\WebAssetItem $asset, mixed $recursively = false, string $recursionType = null, \Joomla\CMS\WebAsset\WebAssetItem $recursionRoot = null)
/**
* Return dependencies for Asset as array of WebAssetItem objects
*
* @param string $type The asset type, script or style
* @param WebAssetItem $asset Asset instance
* @param boolean $recursively Whether to search for dependency recursively
* @param string $recursionType The type of initial item to prevent loop
* @param WebAssetItem $recursionRoot Initial item to prevent loop
*
* @return array
*
* @throws UnsatisfiedDependencyException When Dependency cannot be found
*
* @since 4.0.0
*/
protected function getDependenciesForAsset(string $type, WebAssetItem $asset, $recursively = false, string $recursionType = null, WebAssetItem $recursionRoot = null) : array
{
$assets = [];
$recursionRoot = $recursionRoot ?? $asset;
$recursionType = $recursionType ?? $type;
foreach ($asset->getDependencies() as $depName) {
$depType = $type;
// Skip already loaded in recursion
if ($recursionRoot->getName() === $depName && $recursionType === $depType) {
continue;
}
if (!$this->registry->exists($depType, $depName)) {
throw new UnsatisfiedDependencyException(sprintf('Unsatisfied dependency "%s" for an asset "%s" of type "%s"', $depName, $asset->getName(), $depType));
}
$dep = $this->registry->get($depType, $depName);
$assets[$depType][$depName] = $dep;
if (!$recursively) {
continue;
}
$parentDeps = $this->getDependenciesForAsset($depType, $dep, true, $recursionType, $recursionRoot);
$assets = array_replace_recursive($assets, $parentDeps);
}
return $assets;
}