2021-08-19 14:00:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2021-09-02 16:34:25 +00:00
|
|
|
namespace App\Views\Components;
|
2021-08-19 14:00:14 +00:00
|
|
|
|
2021-08-27 10:58:22 +00:00
|
|
|
use Exception;
|
2021-08-19 14:00:14 +00:00
|
|
|
use ViewComponents\Component;
|
|
|
|
|
|
|
|
class Icon extends Component
|
|
|
|
{
|
|
|
|
public string $glyph = '';
|
|
|
|
|
|
|
|
public function render(): string
|
|
|
|
{
|
2021-08-27 10:58:22 +00:00
|
|
|
try {
|
|
|
|
$svgContents = file_get_contents('assets/icons/' . $this->glyph . '.svg');
|
|
|
|
} catch (Exception) {
|
|
|
|
return '□';
|
|
|
|
}
|
2021-08-19 14:00:14 +00:00
|
|
|
|
2022-09-28 15:02:09 +00:00
|
|
|
unset($this->attributes['glyph']);
|
|
|
|
$attributes = stringify_attributes($this->attributes);
|
2021-08-19 14:00:14 +00:00
|
|
|
|
2022-09-28 15:02:09 +00:00
|
|
|
return str_replace('<svg', '<svg ' . $attributes, $svgContents);
|
2021-08-19 14:00:14 +00:00
|
|
|
}
|
|
|
|
}
|