讨论数量:
enum StorageProvider: string implements HasLabel, HasIcons, HasDescriptions, HasColor
{
use WithOptions;
case Oss = 'oss';
case S3 = 's3';
case Qiniu = 'qiniu';
case Local = 'local';
public function getLabel(): ?string
{
return match($this) {
static::Local => '本地服务器 (Local)',
static::Oss => '阿里云 (OSS)',
static::S3 => '亚马逊 (Amazon S3)',
static::Qiniu => '七牛云 (Kodo)',
};
}
public function getColor(): string | array | null
{
return match($this) {
static::Local => 'text-gray-700 dark:text-gray-400',
static::Oss => 'text-warning-400 dark:text-warning-500',
static::S3 => 'text-warning-400 dark:text-warning-500',
static::Qiniu => 'text-info-400 dark:text-info-500',
};
}
public function getDescriptions(): ?string
{
return '';
}
public function getIcons(): ?string
{
return match($this) {
static::Local => 'heroicon-o-computer-desktop',
static::Oss => 'module-settings::components.icons.aliyun',
static::S3 => 'module-settings::components.icons.amazon',
static::Qiniu => 'module-settings::components.icons.qiniu',
};
}
}
RadioDeck::make('default_provider')
->label(__('module-settings::pages/settings-page.form.storage.default_provider.label'))
->helperText(__('module-settings::pages/settings-page.form.storage.default_provider.help'))
->options(StorageProvider::class)
->icons(StorageProvider::class)
->descriptions(StorageProvider::class)
->required()
时间格式
use DateTimeZone;
use IntlTimeZone;
use Illuminate\Support\Facades\App;
use Symfony\Component\Intl\Timezones;
use Ofcold\ModuleSetting\Enums\TimeFormat;
class Timezone
{
public static function getTimezoneOptions(?string $countryCode = 'CN'): array
{
if (empty($countryCode)) {
return [];
}
$countryTimezones = self::getTimezonesForCountry($countryCode);
if (empty($countryTimezones)) {
return [];
}
$localizedTimezoneNames = Timezones::getNames(App::getLocale());
$results = [];
foreach ($countryTimezones as $timezoneIdentifier) {
$timezoneConical = IntlTimeZone::getCanonicalID($timezoneIdentifier);
$translatedName = $localizedTimezoneNames[$timezoneConical] ?? $timezoneConical;
$cityName = self::extractCityName($translatedName);
$localTime = self::getLocalTime($timezoneIdentifier);
$timezoneAbbreviation = now($timezoneIdentifier)->format('T');
$results[$timezoneIdentifier] = "{$cityName} ({$timezoneAbbreviation}) {$localTime}";
}
return $results;
}
public static function extractCityName(string $translatedName): string
{
if (preg_match('/\((.*?)\)/', $translatedName, $match)) {
return trim($match[1]);
}
return $translatedName;
}
public static function getLocalTime(string $timezone): string
{
return now($timezone)->translatedFormat(TimeFormat::DEFAULT);
}
public static function getTimezonesForCountry(string $countryCode): array
{
return DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, strtoupper($countryCode));
}
}
enum DateFormat: string implements HasLabel
{
// Day-Month-Year Formats
case DMY_SLASH = 'd/m/Y'; // 31/12/2021
case DMY_DASH = 'd-m-Y'; // 31-12-2021
case DMY_DOT = 'd.m.Y'; // 31.12.2021
case DMY_SPACE = 'd m Y'; // 31 12 2021
case DMY_LONG = 'd F Y'; // 31 December 2021
case DMY_SHORT = 'd M Y'; // 31 Dec 2021
// Month-Day-Year Formats
case MDY_SLASH = 'm/d/Y'; // 12/31/2021
case MDY_DASH = 'm-d-Y'; // 12-31-2021
case MDY_DOT = 'm.d.Y'; // 12.31.2021
case MDY_SPACE = 'm d Y'; // 12 31 2021
case MDY_LONG_SPACE = 'F d Y'; // December 31 2021
case MDY_LONG_COMMA = 'F j, Y'; // December 31, 2021
case MDY_SHORT_SPACE = 'M d Y'; // Dec 31 2021
case MDY_SHORT_COMMA = 'M j, Y'; // Dec 31, 2021
// Year-Month-Day Formats
case YMD_SLASH = 'Y/m/d'; // 2021/12/31
case YMD_DASH = 'Y-m-d'; // 2021-12-31
case YMD_DOT = 'Y.m.d'; // 2021.12.31
case YMD_SPACE = 'Y m d'; // 2021 12 31
case YMD_LONG = 'Y F d'; // 2021 December 31
case YMD_SHORT = 'Y M d'; // 2021 Dec 31
public const DEFAULT = self::MDY_SHORT_COMMA->value;
public function getLabel(): ?string
{
return now()->translatedFormat($this->value);
}
}
enum TimeFormat: string implements HasLabel
{
// 12-Hour Formats
case G12_CAP = 'g:i A'; // 5:30 AM
case G12_LOW = 'g:i a'; // 5:30 am
case H12_CAP = 'h:i A'; // 05:30 AM
case H12_LOW = 'h:i a'; // 05:30 am
// 24-Hour Formats
case G24 = 'G:i'; // 5:30
case H24 = 'H:i'; // 05:30
public const DEFAULT = self::G12_CAP->value;
public function getLabel(): ?string
{
return Carbon::createFromTime(5, 30)->translatedFormat($this->value);
}
}
推荐文章: