Files
LarsandCursor 2ded4b7fad
Deploy Test / test (push) Successful in 12s
Deploy Test / deploy (push) Failing after 14s
Ergänze das U1-Fachmodell für Inhalt, Paket und Angebot.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-15 08:39:02 +01:00

62 lines
1.8 KiB
PHP

<?php
namespace App\Domain\Catalog;
class ContentResolver
{
/**
* @return list<array{version_id: int, role: string, path: string}>
*/
public function expand(ContentElementVersion|CompositionVersion $node, string $path = '', array $stack = []): array
{
if ($node instanceof ContentElementVersion) {
$node->loadMissing('element');
return [[
'version_id' => $node->id,
'role' => $path,
'path' => $path !== '' ? $path : $node->element->working_title,
]];
}
if (in_array($node->composition_id, $stack, true)) {
throw new DomainRuleException('Kompositionen dürfen keinen Zyklus bilden.');
}
$stack[] = $node->composition_id;
$rows = [];
foreach ($node->members()->orderBy('position')->get() as $member) {
$segment = $path === '' ? $member->role : $path.' / '.$member->role;
if ($member->content_element_version_id !== null) {
$rows[] = [
'version_id' => $member->content_element_version_id,
'role' => $member->role,
'path' => $segment,
];
continue;
}
$nested = $member->nestedCompositionVersion;
if ($nested === null) {
throw new DomainRuleException('Ein Kompositionsmitglied braucht genau ein Ziel.');
}
$rows = array_merge($rows, $this->expand($nested, $segment, $stack));
}
return $rows;
}
public function resolvedHash(ContentElementVersion|CompositionVersion $node): string
{
$ids = array_values(array_unique(array_column($this->expand($node), 'version_id')));
sort($ids);
return hash('sha256', json_encode($ids, JSON_THROW_ON_ERROR));
}
}