Downloadlinks und Erklärungstexte funktional

This commit is contained in:
Matthias Grief
2024-11-15 23:42:46 +01:00
parent 679bd66f7e
commit 95b21c6305
15 changed files with 106 additions and 63 deletions

View File

@@ -15,6 +15,24 @@ class Util
return preg_replace("/[^a-zA-Z0-9_-]/", "", $string);
}
static function readFileContent(string $filename): string|null
{
if (!file_exists($filename)) {
return null;
}
$file = fopen($filename, "r");
if (!$file) {
return null;
}
$fileContent = fread($file, filesize($filename));
if (!$fileContent) {
return null;
}
fclose($file);
return $fileContent;
}
/**
* Öffnet eine Datei und gibt JSON-Inhalte als Array zurück
* @param string $filename Dateipfad
@@ -22,10 +40,10 @@ class Util
*/
static function parseJsonFromFile(string $filename): mixed
{
$file = fopen($filename, "r") or die("Unable to open file!");
$fileContent = fread($file, filesize($filename));
fclose($file);
return json_decode($fileContent);
$content = self::readFileContent($filename);
if(!isset($content)) {
return null;
}
return json_decode($content);
}
}