You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/app/Services/Cloud/CloudPaidIpChangeFeature.php

44 lines
1.1 KiB
PHP

<?php
namespace App\Services\Cloud;
use App\Models\Configurations;
/** Controls whether the paid public IPv4 replacement is exposed to tenants. */
final class CloudPaidIpChangeFeature
{
public const CONFIG_KEY = 'cloud_paid_ip_change_visible';
public const DEFAULT_VALUE = 'true';
public static function visible(): bool
{
try {
$value = Configurations::where('name', self::CONFIG_KEY)
->value('value');
} catch (\Throwable $error) {
error_log(
'Unable to read the paid IP-change visibility switch: '
. get_class($error)
);
return false;
}
if ($value === null) {
$value = self::DEFAULT_VALUE;
}
return in_array(
strtolower(trim((string) $value)),
['1', 'true', 'yes', 'on'],
true
);
}
public static function assertVisible(): void
{
if (!self::visible()) {
throw new CloudError('付费更换公网 IPv4 当前未向用户开放', 403);
}
}
}