name = $name;
$this->contents = $this->deferContent($contents, $attributes['defer'] ?? false);
unset($attributes['defer']);
$this->attributes = $attributes;
}
public function name(): string
{
return $this->name;
}
public function contents(): string
{
return $this->contents;
}
/**
* This method adds a title element and an aria-labelledby attribute to the SVG.
* To comply with accessibility standards, SVGs should have a title element.
* Check accessibility patterns for icons: https://www.deque.com/blog/creating-accessible-svgs/
*/
public function addTitle(string $title): string
{
// create title element
$titleElement = '
'.$title.'';
// add role attribute to svg element
$this->attributes['role'] = 'img';
// add title element to svg
return preg_replace('/