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.
49 lines
1.4 KiB
PHP
49 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Cloud;
|
|
|
|
use App\Models\Configurations;
|
|
|
|
/**
|
|
* Presentation switch for differentiated network lines.
|
|
*
|
|
* The scheduler schema always retains a default line for every region. A
|
|
* disabled switch therefore hides the choice without changing placement or
|
|
* requiring a future production schema migration.
|
|
*/
|
|
final class CloudNetworkLineFeature
|
|
{
|
|
public const CONFIG_KEY = 'cloud_network_lines_enabled';
|
|
private static $cached = null;
|
|
|
|
public static function enabled(): bool
|
|
{
|
|
if (is_bool(self::$cached)) {
|
|
return self::$cached;
|
|
}
|
|
try {
|
|
$value = Configurations::where('name', self::CONFIG_KEY)
|
|
->value('value');
|
|
} catch (\Throwable $error) {
|
|
error_log('Unable to read the network-line feature switch: '
|
|
. get_class($error));
|
|
return self::$cached = false;
|
|
}
|
|
|
|
return self::$cached = in_array(strtolower(trim((string) $value)),
|
|
['1', 'true', 'yes', 'on'], true);
|
|
}
|
|
|
|
public static function save(bool $enabled): void
|
|
{
|
|
$row = Configurations::where('name', self::CONFIG_KEY)->first();
|
|
if ($row === null) {
|
|
$row = new Configurations();
|
|
$row->name = self::CONFIG_KEY;
|
|
}
|
|
$row->value = $enabled ? 'true' : 'false';
|
|
$row->save();
|
|
self::$cached = $enabled;
|
|
}
|
|
}
|