*/ private static array $cache = []; /** * Return an icon as inline SVG. * * @param string $name Lucide icon name, e.g. "play". * @param string $class CSS classes; the icon is sized by them and colored by currentColor. * @return string Empty when the icon was not copied. */ public static function svg(string $name, string $class = ''): string { self::$cache[$name] ??= self::load($name); if (self::$cache[$name] === '') { return ''; } $attributes = Html::attributes(['class' => $class !== '' ? $class : null, 'aria-hidden' => 'true', 'focusable' => 'false']); return (string) preg_replace('/^ [ 'xmlns' => true, 'width' => true, 'height' => true, 'viewbox' => true, 'fill' => true, 'stroke' => true, 'stroke-width' => true, 'stroke-linecap' => true, 'stroke-linejoin' => true, 'class' => true, 'aria-hidden' => true, 'focusable' => true, ], 'path' => ['d' => true], 'circle' => ['cx' => true, 'cy' => true, 'r' => true], 'rect' => ['x' => true, 'y' => true, 'width' => true, 'height' => true, 'rx' => true], ]); } /** * Read an icon file. * * @param string $name Lucide icon name. * @return string */ private static function load(string $name): string { $file = App::DIR . 'resources/assets/icons/' . sanitize_file_name($name) . '.svg'; return is_readable($file) ? trim((string) file_get_contents($file)) : ''; } }