*/ final class BovinIdentificationProvider implements ProviderInterface { public function __construct( private BovinApiInterface $bovinApi ) {} public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?BovinIdentification { $numeroNational = (string) ($uriVariables['numeroNational'] ?? ''); if ('' === $numeroNational) { return null; } $animalFileDto = $this->bovinApi->getAnimalFile( nationalNumber: $numeroNational, countryCode: 'FR' ); $identificationDto = $animalFileDto->identification; $resource = new BovinIdentification(); $resource->numeroNational = $numeroNational; $resource->sex = $identificationDto?->sex; $resource->breedType = $identificationDto?->breedType; $resource->workNumber = $identificationDto?->workNumber; $resource->birthDate = $identificationDto?->birthDate?->date?->format('Y-m-d'); $resource->birthDateCompletenessFlag = $identificationDto?->birthDate?->completenessFlag; $resource->isFilie = $identificationDto?->isFilie; $resource->motherNationalNumber = $identificationDto?->motherCarrier?->bovin?->nationalNumber; $resource->motherBreedType = $identificationDto?->motherCarrier?->breedType; $resource->fatherNationalNumber = $identificationDto?->fatherIpg?->bovin?->nationalNumber; $resource->fatherBreedType = $identificationDto?->fatherIpg?->breedType; $resource->birthExploitationNumber = $identificationDto?->birthExploitation?->exploitationNumber; foreach ($animalFileDto->presencePeriods as $presencePeriodDto) { $presencePeriod = new PresencePeriod(); $presencePeriod->entryDate = $presencePeriodDto->entry?->date?->format('Y-m-d'); $presencePeriod->entryCause = $presencePeriodDto->entry?->cause; $presencePeriod->exitDate = $presencePeriodDto->exit?->date?->format('Y-m-d'); $presencePeriod->exitCause = $presencePeriodDto->exit?->cause; $resource->presencePeriods[] = $presencePeriod; } return $resource; } }