$locked The locked capabilities the refused call needs. * @param list $plugins Labels of the plugins they belong to. * @param list $unknown Declared IDs no profile knows. */ private function __construct( public readonly array $locked, public readonly array $plugins, public readonly array $unknown ) { parent::__construct(sprintf( '%s locked – %s refused', implode(', ', $plugins) ?: 'unknown capability', implode(', ', $unknown ?: array_map(static fn (FeatureStatus $s): string => $s->feature->id(), $locked)) )); } /** * @param list $locked * @param list $profiles The profiles the locked capabilities belong to. * @throws LogicException When $locked is empty – a lock always names what it locks. */ public static function of(array $locked, array $profiles): self { if ($locked === []) { throw new LogicException('a capability lock needs the locked capabilities'); } return new self($locked, array_map(static fn (Profile $profile): string => $profile->label, $profiles), []); } /** * @param list $ids * @throws LogicException When $ids is empty. */ public static function unknown(array $ids): self { if ($ids === []) { throw new LogicException('an unknown-capability lock needs the IDs'); } return new self([], [], $ids); } public function toError(): WP_Error { if ($this->unknown !== []) { return Errors::make( 'compat_incompatible', sprintf( 'Das Werkzeug verlangt unbekannte Fähigkeiten (%s). Das ist gesperrt. Es wurde nichts geändert.', implode(', ', $this->unknown) ), 'Den Nutzer informieren, dass LIT MCP aktualisiert werden muss.', 423, ['unknown' => $this->unknown] ); } $named = implode(', ', array_map( static fn (FeatureStatus $status): string => '„' . $status->feature->label() . '“', $this->locked )); $plugins = implode(', ', $this->plugins); return Errors::make( 'compat_incompatible', sprintf( '%s ist auf dieser Website nicht mit LIT MCP kompatibel: %s ist gesperrt. Es wurde nichts geändert.', $plugins, $named ), sprintf( 'Gesperrt: %s. Andere Werkzeuge funktionieren weiter. ' . 'Den Nutzer informieren, dass %s geprüft werden muss.', $named, $plugins ), 423, [ 'features' => array_map(static fn (FeatureStatus $status): array => $status->summary(), $this->locked), 'problems' => array_values(array_unique(array_merge( ...array_map(static fn (FeatureStatus $status): array => $status->problems, $this->locked) ))), ] ); } }