>|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; return is_array($entry) ? (bool) ($entry['enabled'] ?? false) : $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]); } 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'); } }