3 namespace BookStack\Util;
7 public function __construct(
8 protected string $name,
9 protected array $attrs = []
13 public function toHtml(): string
15 $attrs = array_merge([
16 'class' => 'svg-icon',
17 'data-icon' => $this->name,
18 'role' => 'presentation',
22 foreach ($attrs as $attrName => $attr) {
23 $attrString .= $attrName . '="' . $attr . '" ';
26 $iconPath = resource_path('icons/' . $this->name . '.svg');
27 $themeIconPath = theme_path('icons/' . $this->name . '.svg');
29 if ($themeIconPath && file_exists($themeIconPath)) {
30 $iconPath = $themeIconPath;
31 } elseif (!file_exists($iconPath)) {
35 $fileContents = file_get_contents($iconPath);
37 return str_replace('<svg', '<svg' . $attrString, $fileContents);