101 lines
2.8 KiB
PHP
101 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace Paymenter\Extensions\Others\NavbarManager\Support;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Str;
|
|
|
|
class RemixIconCatalog
|
|
{
|
|
protected const CACHE_KEY = 'navbar_manager_remix_icon_catalog';
|
|
protected const REMIX_TAGS_URL = 'https://raw.githubusercontent.com/Remix-Design/RemixIcon/master/tags.json';
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
public static function all(): array
|
|
{
|
|
return Cache::remember(self::CACHE_KEY, now()->addDay(), function () {
|
|
try {
|
|
$response = Http::timeout(8)->get(self::REMIX_TAGS_URL);
|
|
if (! $response->successful()) {
|
|
return self::fallback();
|
|
}
|
|
|
|
$json = $response->json();
|
|
if (! is_array($json)) {
|
|
return self::fallback();
|
|
}
|
|
|
|
$icons = [];
|
|
foreach ($json as $group) {
|
|
if (! is_array($group)) {
|
|
continue;
|
|
}
|
|
|
|
foreach ($group as $iconName => $unusedTags) {
|
|
if (! is_string($iconName)) {
|
|
continue;
|
|
}
|
|
|
|
$normalized = self::normalizeIconName($iconName);
|
|
$icons[$normalized] = $normalized;
|
|
}
|
|
}
|
|
|
|
ksort($icons);
|
|
|
|
return ! empty($icons) ? $icons : self::fallback();
|
|
} catch (\Throwable $e) {
|
|
\Log::warning('NavbarManager: Failed to load Remix icon catalog', [
|
|
'error' => $e->getMessage(),
|
|
]);
|
|
|
|
return self::fallback();
|
|
}
|
|
});
|
|
}
|
|
|
|
public static function clearCache(): void
|
|
{
|
|
Cache::forget(self::CACHE_KEY);
|
|
}
|
|
|
|
protected static function fallback(): array
|
|
{
|
|
$icons = [
|
|
'ri-home-line',
|
|
'ri-user-line',
|
|
'ri-settings-3-line',
|
|
'ri-dashboard-line',
|
|
'ri-menu-line',
|
|
'ri-link',
|
|
'ri-folder-line',
|
|
'ri-shopping-bag-3-line',
|
|
'ri-megaphone-line',
|
|
'ri-book-open-line',
|
|
'ri-file-text-line',
|
|
'ri-customer-service-2-line',
|
|
'ri-questionnaire-line',
|
|
'ri-information-line',
|
|
'ri-lock-line',
|
|
'ri-server-line',
|
|
];
|
|
|
|
return array_combine($icons, $icons);
|
|
}
|
|
|
|
protected static function normalizeIconName(string $icon): string
|
|
{
|
|
$icon = Str::lower(trim($icon));
|
|
|
|
if (! Str::startsWith($icon, 'ri-')) {
|
|
$icon = 'ri-' . ltrim($icon, '-');
|
|
}
|
|
|
|
return $icon;
|
|
}
|
|
}
|
|
|