'; public function __construct() { // do nothing } public function read(string $file, bool $firstLine = false) { if (file_exists($file)) { // Read JSON file as array $content = file($file); // Remove first security line if ($firstLine) { unset($content[0]); } // Return JSON as object $content = implode($content); return json_decode($content); } else { return false; } } public function save(object|array $content, string $file, bool $firstLine = false) : bool { // checkTyp if(is_array($content) || is_object($content)) { $content = json_encode($content, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK ); } // check if json is valid $json = json_decode($content); if($json === null){ return false; } else { // save to file LOCK_EX flag prevents that anyone else is writing to the file at the same time $data = ''; if($firstLine) { $data = $this->firstLine.PHP_EOL; } $data .= $content; if (file_put_contents($file, $data, LOCK_EX)) { // on success return true; } else { // on error return false; } } } }