public function addAttributes(array $atts)
{
$html = $this->html;
$key = $this->key;
$replace = function ($tag, $atts, $append) use($html) {
if (false !== ($pos = strrpos($tag, $append))) {
$tag = substr_replace($tag, $html->attributes($atts), $pos) . ' ' . trim($append);
}
return $tag;
};
if ('script' === $this->type) {
$append = '></script>';
$this->filter->add('script_loader_tag', function ($tag, $handle) use($atts, $append, $replace, $key) {
// Check we're only filtering the current asset and not all.
if ($key === $handle) {
return $replace($tag, $atts, $append);
}
return $tag;
});
}
if ('style' === $this->type) {
$append = ' />';
$this->filter->add('style_loader_tag', function ($tag, $handle) use($atts, $append, $replace, $key) {
// Check we're only filtering the current asset and not all.
if ($key === $handle) {
return $replace($tag, $atts, $append);
}
return $tag;
}, 4);
}
return $this;
}