Loheide-eu-mitarbeiterplatt.../app/Plugins/PluginManifest.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

130 lines
4.1 KiB
PHP

<?php
namespace App\Plugins;
use App\Version;
use InvalidArgumentException;
/**
* Inhalt einer plugin.json.
*
* {
* "slug": "mav-kalender",
* "name": "MAV-Kalender",
* "version": "1.0.0",
* "description": "…",
* "author": "…",
* "namespace": "Acme\\MavKalender\\",
* "class": "Acme\\MavKalender\\Plugin",
* "requires": { "core": ">=0.3.0", "php": ">=8.3", "plugins": ["news"] },
* "update_url": "https://…"
* }
*/
final class PluginManifest
{
public const SLUG_PATTERN = '/^[a-z0-9]+(?:-[a-z0-9]+)*$/';
/**
* @param array<string, mixed> $data
*/
private function __construct(
public readonly string $slug,
public readonly string $name,
public readonly string $version,
public readonly string $description,
public readonly string $author,
public readonly string $namespace,
public readonly string $class,
public readonly string $path,
public readonly bool $core,
public readonly array $requires,
public readonly ?string $updateUrl,
public readonly bool $enabledByDefault = true,
) {}
public static function fromDirectory(string $path, bool $core): self
{
$file = rtrim($path, '/').'/plugin.json';
$data = json_decode((string) @file_get_contents($file), true);
if (! is_array($data)) {
throw new InvalidArgumentException('plugin.json fehlt oder ist kein gültiges JSON.');
}
return self::fromArray($data, $path, $core);
}
/**
* @param array<string, mixed> $data
*/
public static function fromArray(array $data, string $path, bool $core): self
{
foreach (['slug', 'name', 'version', 'namespace', 'class'] as $field) {
if (! is_string($data[$field] ?? null) || trim($data[$field]) === '') {
throw new InvalidArgumentException("plugin.json: Feld „{$field}“ fehlt.");
}
}
if (! preg_match(self::SLUG_PATTERN, $data['slug'])) {
throw new InvalidArgumentException('plugin.json: „slug“ darf nur Kleinbuchstaben, Ziffern und Bindestriche enthalten.');
}
$namespace = rtrim($data['namespace'], '\\').'\\';
if (! str_starts_with(ltrim($data['class'], '\\'), $namespace)) {
throw new InvalidArgumentException('plugin.json: „class“ muss im angegebenen Namespace liegen.');
}
if (str_starts_with($namespace, 'App\\') || str_starts_with($namespace, 'Illuminate\\')) {
throw new InvalidArgumentException('plugin.json: Der Namespace „App\\“ ist dem Kern vorbehalten.');
}
return new self(
slug: $data['slug'],
name: $data['name'],
version: $data['version'],
description: (string) ($data['description'] ?? ''),
author: (string) ($data['author'] ?? ''),
namespace: $namespace,
class: ltrim($data['class'], '\\'),
path: rtrim($path, '/'),
core: $core,
requires: is_array($data['requires'] ?? null) ? $data['requires'] : [],
updateUrl: is_string($data['update_url'] ?? null) ? $data['update_url'] : null,
enabledByDefault: (bool) ($data['enabled_by_default'] ?? true),
);
}
/**
* @return list<string>
*/
public function requiredPlugins(): array
{
return array_values(array_filter((array) ($this->requires['plugins'] ?? []), 'is_string'));
}
/**
* Gründe, warum das Plugin in dieser Umgebung nicht laufen kann.
*
* @return list<string>
*/
public function incompatibilities(): array
{
$problems = [];
if (! VersionConstraint::satisfies(Version::VERSION, $this->requires['core'] ?? null)) {
$problems[] = 'benötigt Inhaus '.$this->requires['core'];
}
if (! VersionConstraint::satisfies(PHP_VERSION, $this->requires['php'] ?? null)) {
$problems[] = 'benötigt PHP '.$this->requires['php'];
}
return $problems;
}
public function migrationsPath(): string
{
return $this->path.'/database/migrations';
}
}