Newer
Older

Yassine Doghri
committed
<?php
declare(strict_types=1);
namespace App\Views\Components;

Yassine Doghri
committed

Yassine Doghri
committed
use Exception;

Yassine Doghri
committed
use ViewComponents\Component;
class Icon extends Component
{
public string $glyph = '';
public function render(): string
{

Yassine Doghri
committed
try {
$svgContents = file_get_contents('assets/icons/' . $this->glyph . '.svg');
} catch (Exception) {
return '□';
}

Yassine Doghri
committed

Yassine Doghri
committed
if ($this->attributes['class'] !== '') {
$svgContents = str_replace('<svg', '<svg class="' . $this->attributes['class'] . '"', $svgContents);

Yassine Doghri
committed
}

Yassine Doghri
committed
return $svgContents;