mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-26 00:24:59 +00:00
fix: circular reference problems during fetches
- Add code snippet to avoid circular reference in SocialActionNormalizer.php, AccompanyingPeriodWorkEvaluationDocumentNormalizer.php, AccompanyingPeriodWorkEvaluationNormalizer.php, and AccompanyingPeriodWorkNormalizer.php
This commit is contained in:
@@ -43,6 +43,24 @@ class AccompanyingPeriodWorkNormalizer implements \Symfony\Component\Serializer\
|
||||
throw new UnexpectedValueException(sprintf('Object must be an instanceof AccompanyingPeriodWork or null when format is docgen, %s given', get_debug_type($object)));
|
||||
}
|
||||
|
||||
// Prevent circular references
|
||||
if ($object instanceof AccompanyingPeriodWork && 'json' === $format) {
|
||||
$objectHash = spl_object_hash($object);
|
||||
$visitedKey = 'accompanying_period_work_visited';
|
||||
|
||||
if (isset($context[$visitedKey][$objectHash])) {
|
||||
return [
|
||||
'id' => $object->getId(),
|
||||
'type' => 'accompanying_period_work',
|
||||
'startDate' => $object->getStartDate()?->format('c'),
|
||||
'endDate' => $object->getEndDate()?->format('c'),
|
||||
'note' => $object->getNote(),
|
||||
];
|
||||
}
|
||||
|
||||
$context[$visitedKey][$objectHash] = true;
|
||||
}
|
||||
|
||||
$cleanContext = array_filter($context, fn (string|int $key) => !in_array($key, ['docgen:expects', self::IGNORE_WORK], true), ARRAY_FILTER_USE_KEY);
|
||||
|
||||
if (null === $object && 'docgen' === $format) {
|
||||
@@ -106,7 +124,7 @@ class AccompanyingPeriodWorkNormalizer implements \Symfony\Component\Serializer\
|
||||
// then, we add normalization for things which are not into the entity
|
||||
$initial['workflows_availables'] = $this->metadataExtractor->availableWorkflowFor(
|
||||
AccompanyingPeriodWork::class,
|
||||
$object->getId()
|
||||
$object->getId() ?? 0
|
||||
);
|
||||
|
||||
$initial['workflows_availables_evaluation'] = $this->metadataExtractor->availableWorkflowFor(
|
||||
@@ -119,7 +137,7 @@ class AccompanyingPeriodWorkNormalizer implements \Symfony\Component\Serializer\
|
||||
|
||||
$workflows = $this->entityWorkflowRepository->findBy([
|
||||
'relatedEntityClass' => AccompanyingPeriodWork::class,
|
||||
'relatedEntityId' => $object->getId(),
|
||||
'relatedEntityId' => $object->getId() ?? 0,
|
||||
]);
|
||||
|
||||
$initial['workflows'] = $this->normalizer->normalize($workflows, 'json', $context);
|
||||
|
Reference in New Issue
Block a user