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
|
|
|
|
2021-08-27 10:58:22 +00:00
|
|
|
if ($this->attributes['class'] !== '') {
|
|
|
|
$svgContents = str_replace('<svg', '<svg class="' . $this->attributes['class'] . '"', $svgContents);
|
2021-08-19 14:00:14 +00:00
|
|
|
}
|
|
|
|
|
2021-08-27 10:58:22 +00:00
|
|
|
return $svgContents;
|
2021-08-19 14:00:14 +00:00
|
|
|
}
|
|
|
|
}
|