normalized label => true */ private array $labels = []; private function __construct( string $kind, string $group = '', array $labels = [] ) { $this->kind = $kind; $this->group = $group; foreach ( $labels as $label ) { if ( ! is_string( $label ) ) { continue; } $normalized = Variable_Ownership_Ledger::normalize_label( $label ); if ( '' !== $normalized ) { $this->labels[ $normalized ] = true; } } } /** Absence proves nothing. The default, and what every unrecognised input becomes. */ public static function none(): self { return new self( self::NO_DELETION ); } /** * The caller holds the complete source; deletion is limited to the labels given, in one group. * * An unknown group key degrades to NO_DELETION rather than to full authority -- a malformed * scope must never widen what may be destroyed. An empty label set is legitimate and means * "this group owns nothing deletable", never "delete anything". * * @param string $group Group key (one of GROUPS). * @param string[] $labels Labels get_variable_part_key() placed in that group. */ public static function scoped_authoritative( string $group, array $labels ): self { $group = sanitize_key( $group ); if ( ! in_array( $group, self::GROUPS, true ) ) { return self::none(); } return new self( self::SCOPED_AUTHORITATIVE, $group, $labels ); } public function kind(): string { return $this->kind; } public function group(): string { return $this->group; } public function allows_any_deletion(): bool { return self::NO_DELETION !== $this->kind; } /** * May a managed label absent from the authoritative payload be soft-deleted? * * Under scoped authority a label get_variable_part_key() did not place in the chosen group is simply * not deletable here -- an unclassified or out-of-group label is left alone rather than being * swept in. */ public function may_delete( string $label ): bool { if ( self::NO_DELETION === $this->kind ) { return false; } return isset( $this->labels[ Variable_Ownership_Ledger::normalize_label( $label ) ] ); } }