userRepository = $userRepository; } /** * @param CommentEmbeddable $object * * @throws ExceptionInterface */ public function normalize($object, ?string $format = null, array $context = []): array { if (null === $object) { return [ 'comment' => '', 'isNull' => true, 'date' => $this->normalizer->normalize(null, $format, array_merge($context, [ 'docgen:expects' => DateTime::class, ])), 'user' => $this->normalizer->normalize(null, $format, array_merge($context, [ 'docgen:expects' => User::class, ])), ]; } $user = $this->userRepository->find($object->getUserId()); return [ 'comment' => $object->getComment(), 'isNull' => false, 'date' => $this->normalizer->normalize($object->getDate(), $format, array_merge($context, [ 'docgen:expects' => DateTime::class, ])), 'user' => $this->normalizer->normalize($user, $format, array_merge($context, [ 'docgen:expects' => User::class, ])), ]; } public function supportsNormalization($data, ?string $format = null, array $context = []): bool { if ('docgen' !== $format) { return false; } if ($data instanceof CommentEmbeddable) { return true; } if ( null === $data && array_key_exists('docgen:expects', $context) && CommentEmbeddable::class === $context['docgen:expects']) { return true; } return false; } }