mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-27 17:15:02 +00:00
Undo inadequate fix of normalizers
This commit is contained in:
@@ -29,31 +29,16 @@ class AccompanyingPeriodWorkEvaluationDocumentNormalizer implements \Symfony\Com
|
|||||||
|
|
||||||
public function normalize($object, ?string $format = null, array $context = []): array
|
public function normalize($object, ?string $format = null, array $context = []): array
|
||||||
{
|
{
|
||||||
// Prevent circular references
|
|
||||||
$objectHash = spl_object_hash($object);
|
|
||||||
$visitedKey = 'evaluation_document_visited';
|
|
||||||
|
|
||||||
if (isset($context[$visitedKey][$objectHash])) {
|
|
||||||
return [
|
|
||||||
'id' => $object->getId(),
|
|
||||||
'type' => 'accompanying_period_work_evaluation_document',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
$context[$visitedKey][$objectHash] = true;
|
|
||||||
|
|
||||||
$initial = $this->normalizer->normalize($object, $format, array_merge($context, [
|
$initial = $this->normalizer->normalize($object, $format, array_merge($context, [
|
||||||
self::SKIP => spl_object_hash($object),
|
self::SKIP => spl_object_hash($object),
|
||||||
]));
|
]));
|
||||||
|
|
||||||
$initial['workflows_availables'] = $this->metadataExtractor->availableWorkflowFor(
|
$initial['workflows_availables'] = $this->metadataExtractor->availableWorkflowFor(
|
||||||
AccompanyingPeriodWorkEvaluationDocument::class,
|
AccompanyingPeriodWorkEvaluationDocument::class,
|
||||||
$object->getId() ?? 0
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$workflows = $this->entityWorkflowRepository->findBy([
|
$workflows = $this->entityWorkflowRepository->findBy([
|
||||||
'relatedEntityClass' => AccompanyingPeriodWorkEvaluationDocument::class,
|
'relatedEntityClass' => AccompanyingPeriodWorkEvaluationDocument::class,
|
||||||
'relatedEntityId' => $object->getId() ?? 0,
|
|
||||||
]);
|
]);
|
||||||
$initial['workflows'] = $this->normalizer->normalize($workflows, 'json', $context);
|
$initial['workflows'] = $this->normalizer->normalize($workflows, 'json', $context);
|
||||||
|
|
||||||
|
@@ -33,22 +33,8 @@ class AccompanyingPeriodWorkEvaluationNormalizer implements \Symfony\Component\S
|
|||||||
*/
|
*/
|
||||||
public function normalize($object, ?string $format = null, array $context = []): array
|
public function normalize($object, ?string $format = null, array $context = []): array
|
||||||
{
|
{
|
||||||
// Prevent circular references
|
|
||||||
$objectHash = spl_object_hash($object);
|
|
||||||
$visitedKey = 'evaluation_visited';
|
|
||||||
|
|
||||||
if (isset($context[$visitedKey][$objectHash])) {
|
|
||||||
return [
|
|
||||||
'id' => $object->getId(),
|
|
||||||
'type' => 'accompanying_period_work_evaluation',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
$context[$visitedKey][$objectHash] = true;
|
|
||||||
|
|
||||||
$initial = $this->normalizer->normalize($object, $format, array_merge(
|
$initial = $this->normalizer->normalize($object, $format, array_merge(
|
||||||
$context,
|
$context,
|
||||||
[self::IGNORE_EVALUATION => spl_object_hash($object)]
|
|
||||||
));
|
));
|
||||||
|
|
||||||
// due to bug: https://api-platform.com/docs/core/serialization/#collection-relation
|
// due to bug: https://api-platform.com/docs/core/serialization/#collection-relation
|
||||||
@@ -64,12 +50,10 @@ class AccompanyingPeriodWorkEvaluationNormalizer implements \Symfony\Component\S
|
|||||||
|
|
||||||
$initial['workflows_availables'] = $this->metadataExtractor->availableWorkflowFor(
|
$initial['workflows_availables'] = $this->metadataExtractor->availableWorkflowFor(
|
||||||
AccompanyingPeriodWorkEvaluation::class,
|
AccompanyingPeriodWorkEvaluation::class,
|
||||||
$object->getId() ?? 0
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$workflows = $this->entityWorkflowRepository->findBy([
|
$workflows = $this->entityWorkflowRepository->findBy([
|
||||||
'relatedEntityClass' => AccompanyingPeriodWorkEvaluation::class,
|
'relatedEntityClass' => AccompanyingPeriodWorkEvaluation::class,
|
||||||
'relatedEntityId' => $object->getId() ?? 0,
|
|
||||||
]);
|
]);
|
||||||
$initial['workflows'] = $this->normalizer->normalize($workflows, 'json', $context);
|
$initial['workflows'] = $this->normalizer->normalize($workflows, 'json', $context);
|
||||||
|
|
||||||
|
@@ -42,25 +42,6 @@ class AccompanyingPeriodWorkNormalizer implements \Symfony\Component\Serializer\
|
|||||||
if ('docgen' === $format && !($object instanceof AccompanyingPeriodWork || null === $object)) {
|
if ('docgen' === $format && !($object instanceof AccompanyingPeriodWork || null === $object)) {
|
||||||
throw new UnexpectedValueException(sprintf('Object must be an instanceof AccompanyingPeriodWork or null when format is docgen, %s given', get_debug_type($object)));
|
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);
|
$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) {
|
if (null === $object && 'docgen' === $format) {
|
||||||
@@ -124,7 +105,6 @@ class AccompanyingPeriodWorkNormalizer implements \Symfony\Component\Serializer\
|
|||||||
// then, we add normalization for things which are not into the entity
|
// then, we add normalization for things which are not into the entity
|
||||||
$initial['workflows_availables'] = $this->metadataExtractor->availableWorkflowFor(
|
$initial['workflows_availables'] = $this->metadataExtractor->availableWorkflowFor(
|
||||||
AccompanyingPeriodWork::class,
|
AccompanyingPeriodWork::class,
|
||||||
$object->getId() ?? 0
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$initial['workflows_availables_evaluation'] = $this->metadataExtractor->availableWorkflowFor(
|
$initial['workflows_availables_evaluation'] = $this->metadataExtractor->availableWorkflowFor(
|
||||||
@@ -137,7 +117,6 @@ class AccompanyingPeriodWorkNormalizer implements \Symfony\Component\Serializer\
|
|||||||
|
|
||||||
$workflows = $this->entityWorkflowRepository->findBy([
|
$workflows = $this->entityWorkflowRepository->findBy([
|
||||||
'relatedEntityClass' => AccompanyingPeriodWork::class,
|
'relatedEntityClass' => AccompanyingPeriodWork::class,
|
||||||
'relatedEntityId' => $object->getId() ?? 0,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$initial['workflows'] = $this->normalizer->normalize($workflows, 'json', $context);
|
$initial['workflows'] = $this->normalizer->normalize($workflows, 'json', $context);
|
||||||
|
Reference in New Issue
Block a user