/**
* Method to get the asset id from the asset key.
*
* @param integer|string $assetKey The asset key (asset id or asset name).
*
* @return integer The asset id.
*
* @since 3.7.0
*/
protected static function getAssetId($assetKey)
{
static $loaded = array();
// If the asset is already an id return it.
if (is_numeric($assetKey)) {
return (int) $assetKey;
}
if (!isset($loaded[$assetKey])) {
// It's the root asset.
if (self::$rootAssetId !== null && $assetKey === self::$preloadedAssets[self::$rootAssetId]) {
$loaded[$assetKey] = self::$rootAssetId;
} else {
$preloadedAssetsByName = array_flip(self::$preloadedAssets);
// If we already have the asset name stored in preloading, example, a component, no need to fetch it from table.
if (isset($preloadedAssetsByName[$assetKey])) {
$loaded[$assetKey] = $preloadedAssetsByName[$assetKey];
} else {
$table = new Asset(Factory::getDbo());
$table->load(array('name' => $assetKey));
$loaded[$assetKey] = $table->id;
}
}
}
return (int) $loaded[$assetKey];
}