jsonedit/src/Settings.php

32 lines
857 B
PHP
Raw Normal View History

2024-10-02 00:53:11 +02:00
<?php
namespace NoccyLabs\JsonEdit;
2024-10-02 00:53:11 +02:00
class Settings
{
public static bool $editorQuotedKeys = false;
public static function load(string $filename): void
{
if (file_exists($filename) && is_readable($filename)) {
$data = json_decode(file_get_contents($filename));
self::$editorQuotedKeys = $data->editorQuotedKeys ?? false;
}
}
public static function save(string $filename): void
{
$data = json_encode([
'editorQuotedKeys' => self::$editorQuotedKeys
], JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT)."\n";
@file_put_contents($filename, $data);
}
public static function set(string $key, mixed $value): void
{
switch ($key) {
case 'editorQuotedKeys':
self::$editorQuotedKeys = (bool)$value; break;
}
}
}