>|null */ private ?array $data = null; public function __construct(private readonly ?string $file = null) {} public function isEnabled(PluginManifest $manifest): bool { $entry = $this->all()[$manifest->slug] ?? null; // Ein Eintrag kann auch nur einen vermerkten Absturz enthalten – dann gilt die Voreinstellung return is_array($entry) && array_key_exists('enabled', $entry) ? (bool) $entry['enabled'] : $manifest->core && ($manifest->enabledByDefault || self::$enableOptionalCorePlugins); } public function setEnabled(string $slug, bool $enabled, ?string $reason = null): void { $this->update($slug, ['enabled' => $enabled, 'disabled_reason' => $enabled ? null : $reason, 'disabled_at' => $enabled ? null : time(), 'crashed_at' => null]); } /** Letzter Absturz beim Laden, der das Plugin noch nicht abgeschaltet hat (Unix-Zeit) */ public function crashedAt(string $slug): ?int { $this->data = null; // frisch lesen – eine parallele Anfrage kann ihn eben vermerkt haben $at = $this->all()[$slug]['crashed_at'] ?? null; return is_int($at) ? $at : null; } public function recordCrash(string $slug): void { $this->update($slug, ['crashed_at' => time()]); } /** Zeitpunkt der Deaktivierung (Unix-Zeit), falls bekannt */ public function disabledAt(string $slug): ?int { $at = $this->all()[$slug]['disabled_at'] ?? null; return is_int($at) ? $at : null; } public function disabledReason(string $slug): ?string { return $this->all()[$slug]['disabled_reason'] ?? null; } public function forget(string $slug): void { $data = $this->all(); unset($data[$slug]); $this->write($data); } /** * @return array> */ public function all(): array { if ($this->data === null) { $decoded = json_decode((string) @file_get_contents($this->path()), true); $this->data = is_array($decoded) ? $decoded : []; } return $this->data; } /** * @param array $values */ private function update(string $slug, array $values): void { $this->data = null; $data = $this->all(); $data[$slug] = array_merge($data[$slug] ?? [], $values); $this->write($data); } /** * @param array> $data */ private function write(array $data): void { AtomicFile::write($this->path(), json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); $this->data = $data; } private function path(): string { return $this->file ?? storage_path('app/plugins.json'); } }