Deathgarden_Rebirth-Rewrite/dist/app/Models/AbstractFileBasedModel.php
Vari dfbb8f34c0 Added new Admin Tool page to manage the different versions we need to control. These are:
- launcher version (updating launcher)
- game version
- content version (for catalog)
- catalog version

Also added checks that when the wrong content version you dont get a catalog until you update tha game. And added another check when queuing when using the wrong game version you dont get queued. (so that hunters on the wrong version cannot block the matchmaking)
2024-09-05 23:43:47 +02:00

41 lines
1.0 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Storage;
abstract class AbstractFileBasedModel
{
const FILE_NAME = 'file-name';
const CACHE_DURATION = 3600;
protected static ?FilesystemAdapter $disk = null;
public function save(): bool|string {
$success = static::getDisk()->put(static::FILE_NAME, serialize($this));
if($success === true)
Cache::forget(static::FILE_NAME);
return $success;
}
public static function get(): ?static {
return Cache::remember(
static::FILE_NAME,
static::CACHE_DURATION,
function () {
$data = static::getDisk()->get(static::FILE_NAME);
return $data === null ? null : unserialize($data);
}
);
}
protected static function getDisk(): FilesystemAdapter {
return static::$disk ?? static::$disk = Storage::disk('local');
}
}