personRender = $personRender; $this->translator = $translator; $this->translatableStringHelper = $translatableStringHelper; } public function normalize($person, string $format = null, array $context = []) { /** @var Person $person */ $dateContext = $context; $dateContext['docgen:expects'] = \DateTimeInterface::class; if (null === $person) { return $this->normalizeNullValue($format, $context); } return [ 'firstname' => $person->getFirstName(), 'lastname' => $person->getLastName(), 'altNames' => \implode( ', ', \array_map( function (PersonAltName $altName) { return $altName->getLabel(); }, $person->getAltNames()->toArray() ) ), 'text' => $this->personRender->renderString($person, []), 'birthdate' => $this->normalizer->normalize($person->getBirthdate(), $format, $dateContext), 'deathdate' => $this->normalizer->normalize($person->getDeathdate(), $format, $dateContext), 'gender' => $this->translator->trans($person->getGender()), 'maritalStatus' => null !== ($ms = $person->getMaritalStatus()) ? $this->translatableStringHelper->localize($ms->getName()) : '', 'maritalStatusDate' => $this->normalizer->normalize($person->getMaritalStatusDate(), $format, $dateContext), 'email' => $person->getEmail(), 'firstPhoneNumber' => $person->getPhonenumber() ?? $person->getMobilenumber(), 'fixPhoneNumber' => $person->getPhonenumber(), 'mobilePhoneNumber' => $person->getMobilenumber(), 'nationality' => null !== ($c = $person->getNationality()) ? $this->translatableStringHelper->localize($c->getName()) : '', 'placeOfBirth' => $person->getPlaceOfBirth(), 'memo' => $person->getMemo(), 'numberOfChildren' => (string) $person->getNumberOfChildren(), ]; } private function normalizeNullValue(string $format, array $context) { $normalizer = new NormalizeNullValueHelper($this->normalizer); $attributes = [ 'firstname', 'lastname', 'altNames', 'text', 'birthdate' => \DateTimeInterface::class, 'deathdate' => \DateTimeInterface::class, 'gender', 'maritalStatus', 'maritalStatusDate' => \DateTimeInterface::class, 'email', 'firstPhoneNumber', 'fixPhoneNumber', 'mobilePhoneNumber', 'nationality', 'placeOfBirth', 'memo', 'numberOfChildren' ]; return $normalizer->normalize($attributes, $format, $context); } public function supportsNormalization($data, string $format = null, array $context = []) { if ($format !== 'docgen') { return false; } return $data instanceof Person || ( \array_key_exists('docgen:expects', $context) && $context['docgen:expects'] === Person::class ); } }