Downloadlinks und Erklärungstexte funktional
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user