Files
jsonedit/src/Settings.php

57 lines
1.8 KiB
PHP

<?php
namespace NoccyLabs\JsonEdit;
class Settings
{
public static bool $editorQuotedKeys = false;
public static bool $compactGroups = false;
public static bool $indentationGuides = true;
public static bool $collapseBefore = true;
public static bool $highlightRow = true;
public static bool $tailLine = true;
public static bool $highlightIndices = true;
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;
self::$compactGroups = $data->compactGroups ?? false;
self::$indentationGuides = $data->indentationGuides ?? true;
self::$collapseBefore = $data->collapseBefore ?? true;
self::$tailLine = $data->tailLine ?? true;
self::$highlightIndices = $data->highlightIndices ?? true;
}
}
public static function save(string $filename): void
{
$data = json_encode([
'editorQuotedKeys' => self::$editorQuotedKeys,
'compactGroups' => self::$compactGroups,
'indentationGuides' => self::$indentationGuides,
'collapseBefore' => self::$collapseBefore,
'highlightRow' => self::$highlightRow,
'tailLine' => self::$tailLine,
'highlightIndices' => self::$highlightIndices,
], 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;
case 'compactGroups':
self::$compactGroups = (bool)$value; break;
}
}
}