feat(skeleton) : wire skeleton writes to SkeletonStructureService

ModelType.setStructure() now stores data in pendingStructure instead of
writing to JSON columns. A new ModelTypeProcessor intercepts API Platform
POST/PUT/PATCH operations and delegates skeleton writes to
SkeletonStructureService, which persists to relation tables.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Matthieu
2026-03-12 18:03:32 +01:00
parent e2326064ba
commit 77c5d25cea
2 changed files with 62 additions and 15 deletions

View File

@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace App\State;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProcessorInterface;
use App\Entity\ModelType;
use App\Service\SkeletonStructureService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
final class ModelTypeProcessor implements ProcessorInterface
{
public function __construct(
#[Autowire(service: 'api_platform.doctrine.orm.state.persist_processor')]
private readonly ProcessorInterface $decorated,
private readonly SkeletonStructureService $skeletonStructureService,
private readonly EntityManagerInterface $entityManager,
) {}
/**
* @param array<string, mixed> $uriVariables
* @param array<string, mixed> $context
*/
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): mixed
{
if (!$data instanceof ModelType) {
return $this->decorated->process($data, $operation, $uriVariables, $context);
}
$pendingStructure = $data->getPendingStructure();
// Persist the entity first (handles all non-skeleton fields)
$result = $this->decorated->process($data, $operation, $uriVariables, $context);
// If structure was provided in the payload, write it to skeleton relation tables
if (null !== $pendingStructure) {
$this->skeletonStructureService->updateSkeletonRequirements($data, $pendingStructure);
$data->clearPendingStructure();
$this->entityManager->flush();
}
return $result;
}
}