Loheide-eu-mitarbeiterplatt.../app/Plugins/PluginState.php
Friederich Loheide ee8dde93c0
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m18s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m21s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m40s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m34s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 3m8s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 3m6s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m43s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m47s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m1s
Feste Profilfelder in Formularen, Geburtstage, anpassbare Startseite
- Formulare: Felder fest aus dem Profil (nicht änderbar, Server setzt den
  Profilwert ein), Hinweis bei fehlender Profilangabe
- Geburtstage (optionales Plugin, standardmäßig aus): Tag und Monat freiwillig
  im Profil, Kachel, Liste /geburtstage, Pagebuilder-Block, Glückwunsch am
  eigenen Geburtstag; Sichtbarkeit alle/Abteilung/Standort
- Startseite: Kacheln je Bereich sortieren und ausblenden; eigene Kacheln
  (Bild mit Link, Text, Hinweis) mit Zeitraum und Zielgruppe
- Kern: optionale mitgelieferte Plugins, Startseitenbereich „top“,
  Profilabschnitte für Plugins, Kachel-Bezeichnungen

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 09:51:19 +00:00

87 lines
2.6 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Plugins;
use App\Support\Update\AtomicFile;
/**
* Aktivierungszustand der Plugins in storage/app/plugins.json – als Datei, damit
* das Laden der Plugins keine Datenbankabfrage kostet und auch ohne DB klappt.
* Mitgelieferte Plugins sind aktiv, solange nichts anderes vermerkt ist – außer sie
* sind als optional markiert („enabled_by_default“: false in plugin.json).
*/
class PluginState
{
/**
* Test-Suite: optionale mitgelieferte Plugins ebenfalls laden, damit ihre
* Tabellen und Tests dabei sind (gesetzt in tests/TestCase.php).
*/
public static bool $enableOptionalCorePlugins = false;
/** @var array<string, array<string, mixed>>|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<string, array<string, mixed>>
*/
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<string, mixed> $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<string, array<string, mixed>> $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');
}
}