/**
* Add Asset to registry of known assets
*
* @param string $type Asset type, script or style
* @param WebAssetItemInterface $asset Asset instance
*
* @return self
*
* @since 4.0.0
*/
public function add(string $type, WebAssetItemInterface $asset) : WebAssetRegistryInterface
{
$type = strtolower($type);
if (!array_key_exists($type, $this->assets)) {
$this->assets[$type] = [];
}
$eventChange = 'new';
$eventAsset = $asset;
// Use "old" asset for "Changed" event, a "new" asset can be loaded by a name from the registry
if (!empty($this->assets[$type][$asset->getName()])) {
$eventChange = 'override';
$eventAsset = $this->assets[$type][$asset->getName()];
}
$this->assets[$type][$asset->getName()] = $asset;
$this->dispatchAssetChanged($type, $eventAsset, $eventChange);
return $this;
}