Files
fewo-stommer/app/Process/Models/ProcessModel.php
T
LarsandClaude Sonnet 5.5 e95ba4f986 Schablonenkomposition: Basisprozess external.booking mit Platz für Finanz- und Dokumentenschablonen
Vier Schablonen (Eigenes/Portal-Inkasso, Eigene/Externe Vertragsdokumentation) in
app/Process/Templates, TemplateComposer prüft Ergebnisse, Verantwortlichkeiten, Ausschlüsse
und harte Modulabhängigkeiten. Der Plan friert die Schablonenversionen ein. A3–A5 bleiben
als Voreinstellungen; die vierte Kombination (eigenes Inkasso + externe Unterlagen) ist
darstellbar. Konfigurator-Logik und ConfigureChannelProcess kennen die Schablonenwahl.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-05 10:48:49 +01:00

174 lines
5.2 KiB
PHP

<?php
namespace App\Process\Models;
use App\Enums\CaseType;
use App\Enums\IntakeKind;
use App\Enums\ProcessSetting;
use App\Process\ProcessCatalogue;
use App\Process\Templates\TemplateArea;
/**
* A centrally defined, versioned process model (docs/Prozessarchitektur/Architektur/02 §5): its course of steps with
* extension points, its admissible variants and the responsibilities it fixes. The case type stays the derived
* classification (ProcessProfile::caseTypeFor); a model only declares which case types it is admissible for.
* The landlord chooses among models, he never defines one.
*/
abstract class ProcessModel
{
abstract public static function key(): string;
abstract public static function version(): int;
abstract public static function label(): string;
abstract public static function description(): string;
/** @return list<CaseType> */
abstract public static function caseTypes(): array;
/** @return list<IntakeKind> */
abstract public static function intakes(): array;
abstract public static function responsibilities(): Responsibilities;
/** @return list<Step> */
abstract public function steps(): array;
/**
* What a channel must be able to do (and not do) for this model to fit: capability key => required value. Empty:
* the model fits every channel that delivers its intake kind (docs/Prozessarchitektur/V2.1/02 §3.2).
*
* @return array<string, bool>
*/
public static function capabilityRequirements(): array
{
return [];
}
/**
* Settings the model fixes for its cases (e.g. the pre-reservation of the offer model).
*
* @return array<string, string|int|bool>
*/
public static function fixes(): array
{
return [];
}
/**
* @return list<Variant>
*/
public function variants(): array
{
return [Variant::make('standard', 'Standard')];
}
public function variant(string $key): ?Variant
{
foreach ($this->variants() as $variant) {
if ($variant->key === $key) {
return $variant;
}
}
return null;
}
/**
* The function template areas this model offers a slot for (empty: the model's course is fixed).
*
* @return list<TemplateArea>
*/
public function slots(): array
{
return array_values(array_map(fn (Step $step): TemplateArea => $step->slot, array_filter($this->steps(), fn (Step $step): bool => $step->isSlot())));
}
/**
* The results the base course provides to the templates of its slots (see FunctionTemplate::requires()).
*
* @return list<string>
*/
public static function providedResults(): array
{
return [];
}
/**
* The template (key) every slot gets when none was chosen: area value => template key.
*
* @return array<string, string>
*/
public static function defaultTemplates(): array
{
return [];
}
/**
* Whether the model is kept for compatibility (existing channels and frozen plans) and no longer offered as a
* choice: its combination is a preset of a composable model.
*/
public static function isLegacy(): bool
{
return false;
}
/**
* The template combination that reproduces this legacy model (area value => template key), or empty.
*
* @return array<string, string>
*/
public static function presetTemplates(): array
{
return [];
}
/**
* The modules of the course in order, with the variant's modules at their points and the chosen templates' modules
* at their slots.
*
* @param array<string, string> $templates area value => template key or key@version (missing areas: the default)
* @return list<string>
*/
public function modules(?string $variant = 'standard', array $templates = []): array
{
$chosen = $this->variant($variant ?? 'standard');
$catalogue = app(ProcessCatalogue::class);
$modules = [];
foreach ($this->steps() as $step) {
if ($step->isPoint()) {
array_push($modules, ...($chosen?->modulesAt($step->point) ?? []));
} elseif ($step->isSlot()) {
$reference = $templates[$step->slot->value] ?? static::defaultTemplates()[$step->slot->value] ?? null;
if ($reference !== null && ($class = $catalogue->templateClass($reference)) !== null) {
array_push($modules, ...$class::modules());
}
} else {
$modules[] = $step->module;
}
}
return $modules;
}
/**
* @return list<Point>
*/
public function points(): array
{
return array_values(array_map(fn (Step $step): Point => $step->point, array_filter($this->steps(), fn (Step $step): bool => $step->isPoint())));
}
public static function reference(): string
{
return static::key().'@'.static::version();
}
/** Whether the model fixes the setting (the configurator shows it, but not as a choice). */
public static function fixesSetting(ProcessSetting $setting): bool
{
return array_key_exists($setting->value, static::fixes());
}
}