V2.1: Kommunikation nach Medium, Absicht und Wirkung (Fälle E/F)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-05 07:57:54 +01:00
1 parent 8442d0a3d8
commit 8026eceab4
13 files changed
+633 -2

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
<?php
namespace App\Communication;
use App\Enums\Medium;
use App\Enums\MessageEffect;
use App\Enums\MessageIntent;
use App\Support\Settings;
/**
* The medium × intent policy (V2.1): `config/communication.php` is the ceiling, the landlord's `communication_rules`
* (tenants) may only narrow it: switch a medium off, withdraw effects. Widening is ignored.
*/
class CommunicationRules
{
public function mediumActive(Medium $medium): bool
{
$ceiling = (bool) config("communication.media.{$medium->value}.active", false);
return $ceiling && ($this->narrowing()['media'][$medium->value]['active'] ?? true) !== false;
}
public function consentRequired(Medium $medium): bool
{
return (bool) config("communication.media.{$medium->value}.consent_required", false);
}
/**
* @return list<MessageEffect> the effects the rules allow for the intent on the medium (never empty: review at least)
*/
public function effects(Medium $medium, MessageIntent $intent): array
{
/** @var list<MessageEffect> $ceiling */
$ceiling = config('communication.effects.'.$intent->value, [MessageEffect::Review]);
$withdrawn = (array) ($this->narrowing()['effects'][$medium->value][$intent->value] ?? []);
$allowed = array_values(array_filter($ceiling, fn (MessageEffect $effect): bool => ! in_array($effect->value, $withdrawn, true)));
return $allowed === [] ? [MessageEffect::Review] : $allowed;
}
/**
* @return array<string, mixed>
*/
private function narrowing(): array
{
return (array) (Settings::tenant()?->communication_rules ?? []);
}
}