- Plugins nach WordPress-Prinzip: plugin.json-Manifest mit Versions- und Abhängigkeitsprüfung, eigenes PSR-4-Autoloading, register()/boot(), activate()/deactivate()/uninstall(), Migrationen, Routen und Views je Plugin - plugins-core/ (mitgeliefert, aktiv bis zur Deaktivierung) und plugins/ (Kunden-Plugins, geschützt vor Updates, inaktiv bis zur Aktivierung) - Zustand in storage/app/plugins.json – Laden ohne Datenbankabfrage - Wiederherstellungsmodus: Ausnahmen und Fatal Errors beim Laden deaktivieren das Plugin, das Portal bleibt erreichbar - Hooks (Actions/Filter mit Prioritäten) und Registries für Navigation, Startseiten-Kacheln, Rechte und Admin-Seiten (Filament-Discovery) - Admin-Seite „Plugins“: aktivieren, deaktivieren, per ZIP installieren (ZIP-Slip-Schutz), löschen mit oder ohne Daten; abschaltbar per INHAUS_DISALLOW_FILE_MODS - Startseite komplett aus Kacheln; Plugin-Seiten als „slug::Seite“ - Version 0.3.0 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
58 lines
1.9 KiB
PHP
58 lines
1.9 KiB
PHP
<?php
|
||
|
||
namespace App\Plugins;
|
||
|
||
/**
|
||
* Einfache Versionsbedingungen für Plugin-Manifeste: „>=1.2“, „<2.0“, „^1.4“,
|
||
* „~1.4“, „1.2.3“, „*“ – mehrere mit Leerzeichen oder Komma verknüpft (UND).
|
||
*/
|
||
final class VersionConstraint
|
||
{
|
||
public static function satisfies(string $version, ?string $constraint): bool
|
||
{
|
||
$constraint = trim((string) $constraint);
|
||
|
||
if ($constraint === '' || $constraint === '*') {
|
||
return true;
|
||
}
|
||
|
||
foreach (preg_split('/[\s,]+/', $constraint) ?: [] as $part) {
|
||
if (! self::check(self::normalize($version), $part)) {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
private static function check(string $version, string $part): bool
|
||
{
|
||
if (str_starts_with($part, '^')) {
|
||
$min = self::normalize(substr($part, 1));
|
||
[$major, $minor] = array_map('intval', explode('.', $min));
|
||
$max = $major > 0 ? ($major + 1).'.0.0' : '0.'.($minor + 1).'.0';
|
||
|
||
return version_compare($version, $min, '>=') && version_compare($version, $max, '<');
|
||
}
|
||
|
||
if (str_starts_with($part, '~')) {
|
||
$min = self::normalize(substr($part, 1));
|
||
[$major, $minor] = array_map('intval', explode('.', $min));
|
||
|
||
return version_compare($version, $min, '>=') && version_compare($version, $major.'.'.($minor + 1).'.0', '<');
|
||
}
|
||
|
||
if (preg_match('/^(>=|<=|>|<|==|=|!=)(.+)$/', $part, $m)) {
|
||
return version_compare($version, self::normalize($m[2]), $m[1] === '=' ? '==' : $m[1]);
|
||
}
|
||
|
||
return version_compare($version, self::normalize($part), '==');
|
||
}
|
||
|
||
private static function normalize(string $version): string
|
||
{
|
||
$parts = explode('.', preg_replace('/[^0-9.].*$/', '', ltrim(trim($version), 'vV')));
|
||
|
||
return implode('.', array_slice(array_pad(array_map('intval', $parts), 3, 0), 0, 3));
|
||
}
|
||
}
|